发布网友 发布时间:2022-05-12 04:21
共4个回答
热心网友 时间:2023-11-04 17:43
一段获取正在运行的后台service的代码,如下://RunningServicesInfopublic static String getRunningServicesInfo(Context context) {StringBuffer serviceInfo = new StringBuffer();final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);List services = activityManager.getRunningServices(100);Iterator l = services.iterator();while (l.hasNext()) {RunningServiceInfo si = (RunningServiceInfo) l.next();serviceInfo.append("pid: ").append(si.pid);serviceInfo.append("\nprocess: ").append(si.process);serviceInfo.append("\nservice: ").append(si.service);serviceInfo.append("\ncrashCount: ").append(si.crashCount);serviceInfo.append("\nclientCount: ").append(si.clientCount);serviceInfo.append("\nactiveSince: ").append(ToolHelper.formatData(si.activeSince));serviceInfo.append("\nlastActivityTime: ").append(ToolHelper.formatData(si.lastActivityTime));serviceInfo.append("\n\n");}return serviceInfo.toString();}热心网友 时间:2023-11-04 17:43
使用start启动的获取不到,但是可以stop操作就可以了。热心网友 时间:2023-11-04 17:44
public abstract boolean stopService(Intent service)这个操作如何获得service的实例(句柄)热心网友 时间:2023-11-04 17:45
它一直在后台运行~~你可以发送消息给他,关闭它~