Welcome 微信登录

首页 / 操作系统 / Linux / Android 获取正在运行的后台service的代码

获取正在运行的后台service的代码 给一段获取正在运行的后台service的代码,如下: //RunningServicesInfo
        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("pid: ").append(si.pid);
                        serviceInfo.append(" process: ").append(si.process);
                        serviceInfo.append(" service: ").append(si.service);
                        serviceInfo.append(" crashCount: ").append(si.crashCount);
                        serviceInfo.append(" clientCount: ").append(si.clientCount);
                        serviceInfo.append(" activeSince: ").append(ToolHelper.formatData(si.activeSince));
                        serviceInfo.append(" lastActivityTime: ").append(ToolHelper.formatData(si.lastActivityTime));
                        serviceInfo.append(" ");
                }
                return serviceInfo.toString();
        }