Android Service Check isServiceRunning(Context ctx, Class serviceClass)

Here you can find the source of isServiceRunning(Context ctx, Class serviceClass)

Description

is Service Running

License

Open Source License

Declaration

static boolean isServiceRunning(Context ctx, Class<?> serviceClass) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;

public class Main {
    static boolean isServiceRunning(Context ctx, Class<?> serviceClass) {
        ActivityManager manager = (ActivityManager) ctx
                .getSystemService(Context.ACTIVITY_SERVICE);
        for (RunningServiceInfo service : manager
                .getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(
                    service.service.getClassName())) {
                return true;
            }//from w  w w  .java2s  . c  o  m
        }
        return false;
    }
}