1 Android系统提供了一个函数ActivityManager.getRunningServices可以列出当前正在运行的后台服务线程
2
3 private boolean isServiceRunning() {
4 ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
5 for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
6 if ("com.example.MyService".equals(service.service.getClassName())) {
7 return true;
8 }
9 }
10 return false;
11 }
12