How to check if a service is running

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; 
} 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.