How to check whether your service is running in android?

By | October 2, 2011

This example will test whether a service is running in android if you know it’s package name.
Run this sample of code to check this.

private boolean checkMyServiceRunningOrNot() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.example.your_Service".equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

Leave a Reply

Your email address will not be published. Required fields are marked *