1

Possible Duplicate:
android: check if a service is running

I have one services to perform my action, it will run on background indefinite time. I want to monitor the service whether its is running or not. So, I want to create another service to monitor first one.

Is There any other action interfilter to broadcast, service running or not?

Community
  • 1
  • 1
kumar_android
  • 2,273
  • 1
  • 21
  • 30
  • "it will run on background indefinite time" -- why? Users generally do not like this, which is why users will get rid of your services via task killers, "Force Stop" in Settings, etc. – CommonsWare Nov 23 '12 at 13:01
  • @CommonsWare If the user 'force stop' the services, if it is possible to get the notification? – kumar_android Nov 23 '12 at 13:09
  • Absolutely not. By force-stopping your app, the user is indicating that the user does not want your app to run anymore, because your app is ill-behaved. Your process is immediately terminated, and you are not notified of this fact. So, I ask again: why do you have a service that "will run on background indefinite time"? – CommonsWare Nov 23 '12 at 13:10
  • @CommonsWare I want to block camera process in one service and want to watch another service whether it is running or not. If not i want to re-start the service again – kumar_android Nov 23 '12 at 14:12
  • 1
    "I want to block camera process in one service" -- talented programmers use the device admin APIs to control access to the camera, rather than playing childish script-kiddie games with processes and everlasting services. – CommonsWare Nov 23 '12 at 14:15
  • Of course, Admin APIs for disabling camera will work on Android ICS. For the lower version of android, am doing these workaround. – kumar_android Nov 24 '12 at 05:16

1 Answers1

0

You can use getRunningServices(int max) of ActivityManager

ActivityManager actManager = // get the activity manager

int max = ??;

List<ActivityManager.RunningServiceInfo> runningServices = actManager.getRunningServices(max);

for(ActivityManager.RunningServiceInfo runningService : runningServices)
{

   boolean started = runningService.started;
}

Note: this method is only intended for debugging or implementing service management type user interfaces.

  • I want to know, is there any notification available when service is stopped?..or else i want to check this method in services in indfinite time? – kumar_android Nov 23 '12 at 12:53