Android:隐藏我的应用服务,不显示正在运行的程序

时间:2013-09-02 03:20:14

标签: android service

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

1 个答案:

答案 0 :(得分: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         }