is Running Service - Android android.app

Android examples for android.app:ActivityManager

Description

is Running Service

Demo Code

import java.util.List;

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

public class Main {

  public static boolean isRunningService(String classname, Context context) {

    ActivityManager activity = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);

    List<RunningServiceInfo> services = activity.getRunningServices(1000);
    for (RunningServiceInfo runningServiceInfo : services) {
      ComponentName service = runningServiceInfo.service;
      if (service.getClassName().equals(classname)) {
        return true;
      }//from w  w w .  ja  va 2 s .c  o  m
    }
    return false;
  }

}

Related Tutorials