List of usage examples for android.app ActivityManager getRunningTasks
@Deprecated public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException
From source file:Main.java
public static boolean isApplicationInBackground(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 true; }/* ww w . j a v a 2 s .c o m*/ } return false; }
From source file:Main.java
public static boolean isSingleActivity(Context ctx) { ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1); return tasks.get(0).numRunning == 1; }
From source file:Main.java
public static String getTopActivity(Activity context) { ActivityManager manager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return (runningTaskInfos.get(0).topActivity).getShortClassName(); else// w w w .ja v a 2 s .co m return null; }
From source file:Main.java
public static boolean isBackground(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 w w w. j a v a 2 s . c o m } return false; }
From source file:Main.java
@SuppressWarnings("deprecation") public static boolean isAppStart(Context pContext, String packageName) { ActivityManager activityManager = (ActivityManager) pContext.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(100); for (RunningTaskInfo runningTaskInfo : tasksInfo) { if (packageName.equals(runningTaskInfo.topActivity.getPackageName())) { return true; }/*w w w.java 2 s.c om*/ } return false; }
From source file:Main.java
public static String getActivityName(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.RunningTaskInfo info = manager.getRunningTasks(1).get(0); String shortClassName = info.topActivity.getShortClassName(); System.out.println("shortClassName=" + shortClassName); return shortClassName; }
From source file:Main.java
public static boolean isApplicationBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/* w w w. j a v a 2s . co m*/ } return false; }
From source file:Main.java
public static boolean isApplicationBroughtToBackground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = am.getRunningTasks(1); if (!taskInfo.isEmpty()) { ComponentName topActivity = taskInfo.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }/*from w w w .j a v a 2s .c om*/ } return false; }
From source file:Main.java
public static boolean isStackResumed(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); ActivityManager.RunningTaskInfo runningTaskInfo = runningTaskInfos.get(0); return runningTaskInfo.numActivities > 1; }
From source file:Main.java
public static String getTopActivity(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return runningTaskInfos.get(0).topActivity.getClassName(); else/*from w ww.j ava2 s . c om*/ return ""; }