Example usage for android.app ActivityManager getRunningTasks

List of usage examples for android.app ActivityManager getRunningTasks

Introduction

In this page you can find the example usage for android.app ActivityManager getRunningTasks.

Prototype

@Deprecated
public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException 

Source Link

Document

Return a list of the tasks that are currently running, with the most recent being first and older ones after in order.

Usage

From source file:Main.java

public static final String getTopAppPackageName(final Context context) {
    String packageName = null;// w  ww  .j  a  va  2s  . c o m
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> list = am.getRunningTasks(1);
    ComponentName comp = list.get(0).topActivity;
    if (null != comp) {
        packageName = comp.getPackageName();
    }
    return packageName;
}

From source file:Main.java

public static boolean isBackgroundRunning(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }/*from ww w  .jav a2s.  c o  m*/
    }
    return false;
}

From source file:Main.java

public static boolean isApplicationBroughtToBackground(final Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }/*  www. ja  v  a  2  s.  c o  m*/
    }
    return false;
}

From source file:Main.java

public static boolean isTopApp(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> TaskList = am.getRunningTasks(2);
    if (TaskList == null || TaskList.isEmpty()) {
        return false;
    }/*www .j  a  v a2s  . com*/
    RunningTaskInfo rti = TaskList.get(0);
    String tmp = rti.topActivity.getPackageName();
    return tmp.equals(context.getPackageName());
}

From source file:Main.java

public static boolean isApplicationBroughtToBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (tasks != null && !tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }//w  w w. ja v a 2s  . com
    }
    return false;
}

From source file:Main.java

public static boolean isInstalledAppRunning(Context context, String packageName) {
    boolean isAppRunning = false;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> list = am.getRunningTasks(100);
    for (RunningTaskInfo info : list) {
        if (info.topActivity.getPackageName().equals(packageName)
                && info.baseActivity.getPackageName().equals(packageName)) {
            isAppRunning = true;//from  ww  w . ja  va2  s .com
            break;
        }
    }
    return isAppRunning;
}

From source file:Main.java

public static boolean isStart(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(100);
    if (tasks == null || tasks.size() == 0)
        return false;
    String name = "com.mid.market.service.MarketService";
    for (RunningTaskInfo task : tasks) {
        if (task.baseActivity.getClassName().equals(name)) {
            return true;
        }/*from  w w w  .j a  v  a 2  s .co m*/
    }
    return false;
}

From source file:Main.java

public static boolean isApplicationInStackHead(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return false;
        }//www  . jav a2 s . co m
    }
    return true;
}

From source file:Main.java

public static String getTopActivity2(Context ctx) {
    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName());
    ComponentName componentInfo = taskInfo.get(0).topActivity;
    return componentInfo.getPackageName();
}

From source file:Main.java

public static String getTopPackageName(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName cn = activityManager.getRunningTasks(1).get(0).topActivity;
    return cn.getPackageName();
}