Andriod Service的检测与启动
2013-12-29 20:32:23
-
boolean isServiceRunning = false;
- ActivityManager manager = (ActivityManager)ThisApp.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- for (RunningServiceInfo service :manager.getRunningServices(Integer.MAX_VALUE)) {
- if("so.xxxx.WidgetUpdateService".equals(service.service.getClassName()))
- //Service的类名
- {
- isServiceRunning = true;
- }
- }
- if (!isServiceRunning) {
- Intent i = new Intent(context, WidgetUpdateService.class);
- context.startService(i);
- }