is App Alive by checking the RunningAppProcessInfo - Android Android OS

Android examples for Android OS:Process

Description

is App Alive by checking the RunningAppProcessInfo

Demo Code

import java.util.List;

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

public class Main {

  public static boolean isAppAlive(Context context, String packageName) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
    for (int i = 0; i < processInfos.size(); i++) {
      if (processInfos.get(i).processName.equals(packageName)) {

        return true;
      }//  w  w w . j  a va  2 s. c o m
    }
    return false;
  }

}

Related Tutorials