本文实例讲述了Android编程获取手机后台运行服务的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
public static String getRunningServicesInfo(Context context) { StringBuffer serviceInfo = new StringBuffer(); final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> services = activityManager.getRunningServices( 100 ); Iterator<RunningServiceInfo> l = services.iterator(); while (l.hasNext()) { RunningServiceInfo si = (RunningServiceInfo) l.next(); serviceInfo.append( "\npid: " ).append(si.pid); serviceInfo.append( "\n\nname:" ).append(si.service); serviceInfo.append( "\n\nprocess: " ).append(si.process); serviceInfo.append( "\n\nservice: " ).append(si.service); serviceInfo.append( "\n\ncrashCount: " ).append(si.crashCount); serviceInfo.append( "\n\nclientCount: " ).append(si.clientCount); /*serviceInfo.append("\nactiveSince: ").append(ToolHelper.formatData(si.activeSince)); serviceInfo.append("\nlastActivityTime: ").append(ToolHelper.formatData(si.lastActivityTime));*/ serviceInfo.append( "\n============================" ); serviceInfo.append( "\n\n\n" ); } return serviceInfo.toString(); } |
希望本文所述对大家Android程序设计有所帮助。