Android examples for App:App Running
is App Running Top
//package com.java2s; import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; import android.content.Context; public class Main { public static boolean isAppRunningTop(Context context) { ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> list = am.getRunningTasks(1); if (list.size() > 0) { String packageName = context.getPackageName(); RunningTaskInfo topRunningTaskinfo = list.get(0); if (topRunningTaskinfo.topActivity.getPackageName().equals( packageName)) {//from w ww . j a v a 2s .com return true; } } return false; } }