在Android上,如何隐藏我的应用程序服务,使其不会显示在正在运行的程序列表上?据我所知,系统服务没有显示在列表中,我想知道我的应用程序是否可以实现同样的行为。
不,您不能这样做,而系统服务可以。
因为您的应用程序是来宾,而系统服务是主机。
他们故意隐藏系统服务。
并故意展示您的申请。
这是游戏规则。
如果您想知道为什么设置应用程序页面中的运行列表与您通过AM.getRunningServices()编程获得的列表不同,您可能需要花一些时间查看设置应用程序中的源代码。以下是src/com/android/settings/applications/RunningState.java在package/apps/settings中的代码快照。
856 // Retrieve list of services, filtering out anything that definitely
857 // won't be shown in the UI.
858 List<ActivityManager.RunningServiceInfo> services
859 = am.getRunningServices(MAX_SERVICES);
860 int NS = services != null ? services.size() : 0;
861 for (int i=0; i<NS; i++) {
862 ActivityManager.RunningServiceInfo si = services.get(i);
863 // We are not interested in services that have not been started
864 // and don't have a known client, because
865 // there is nothing the user can do about them.
866 if (!si.started && si.clientLabel == 0) {
867 services.remove(i);
868 i--;
869 NS--;
870 continue;
871 }
872 // We likewise don't care about services running in a
873 // persistent process like the system or phone.
874 if ((si.flags&ActivityManager.RunningServiceInfo.FLAG_PERSISTENT_PROCESS)
875 != 0) {
876 services.remove(i);
877 i--;
878 NS--;
879 continue;
880 }
881 }