user533844
user533844

Reputation: 2063

Android check for running services in application

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

Answers (2)

Martin Nuc
Martin Nuc

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

Steve Bergamini
Steve Bergamini

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

Related Questions