is App Running - Android android.app

Android examples for android.app:ActivityManager

Description

is App Running

Demo Code

import java.util.List;

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

public class Main {

  public static boolean isAppRunning(Context context, String PackageName) {
    boolean isStarted = false;
    try {//from   w  w  w  . j av  a  2s.  c om
      ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
      List<RunningAppProcessInfo> run = mActivityManager.getRunningAppProcesses();
      for (RunningAppProcessInfo pro : run) {
        if (pro.processName.equals(PackageName)) {
          isStarted = true;
          break;
        }
      }
    } catch (SecurityException e) {
      e.printStackTrace();
    }
    return isStarted;
  }

}

Related Tutorials