Friday, February 12, 2016

Way to check Android Serivce is running or not

Use below code to check whether service is running or not
private boolean isMyServiceRunning(Class serviceClass) { 
  ActivityManager actManager = (ActivityManager) 
                             getSystemService(Context.ACTIVITY_SERVICE);
  for (RunningServiceInfo service : actManager
    .getRunningServices(Integer.MAX_VALUE)) {
   if (serviceClass.getName().equals(service.service.getClassName())) {
    return true;
   }
  }
  return false;
 }

Advertisement