Answers for "how to get if the service is running in android programmatically"

-1

check if service is running android

Create the method:

private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

And I call it using:
isMyServiceRunning(MyService.class)
Posted by: Guest on May-05-2020

Code answers related to "how to get if the service is running in android programmatically"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language