Reputation: 2063
I have 3 services running in the background in my application. How do I check if they are running or not.
Upvotes: 0
Views: 338
Reputation: 5764
You can iterate through all services and check if one of them matches name of your service.
private boolean isSomeOfMyServicesRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.domain.myapplication".equals(service.service.getClassName()))
return true;
}
return false;
Upvotes: 1
Reputation: 14600
Use a static field in your service to toggle a boolean flag. Then you can check that flag by binding the service to your activities.
Upvotes: 0