0

在 Android 上,如何隐藏我的应用程序服务,使其不显示在正在运行的程序列表中?据我所知,系统服务没有显示在列表中,我想知道我可以为我的应用程序实现相同的行为。

4

1 回答 1

1

不,您不能这样做,而系统服务可以。

因为您的应用程序是来宾,而系统服务是主机。

他们故意隐藏系统服务。

并故意展示您的应用程序。

这是游戏规则。

如果您想知道为什么设置应用程序页面中的运行列表与您通过 AM.getRunningServices() 以编程方式获取的列表不同,您可能需要花一些时间查看设置应用程序中的源代码。以下是 packages/apps/Settings 中 src/com/android/settings/applications/RunningState.java 代码的快照。

 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         }
于 2013-09-02T03:58:10.763 回答