is Service Running - Android android.app

Android examples for android.app:ActivityManager

Description

is Service Running

Demo Code

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

public class Main {

  public static boolean isServiceRunning(Context context, String serviceClassName) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
      if (serviceClassName.equals(service.service.getClassName())) {
        return true;
      }/*from  ww  w.  ja va2 s . co  m*/
    }
    return false;
  }

}

Related Tutorials