Android examples for android.app:ActivityManager
Inspect the highest activity in the left
import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; import android.content.ComponentName; import android.content.Context; public class Main { public static boolean isTopActivity(String name) { ActivityManager activityManager = (ActivityManager) ContextUtil.CONTEXT.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> list = activityManager.getRunningTasks(1); ComponentName cn = list.get(0).topActivity; return cn.getClassName().equals(name); }/*from w w w. j a v a 2 s .co m*/ }