Java tutorial
//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 isTopApp(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> TaskList = am.getRunningTasks(2); if (TaskList == null || TaskList.isEmpty()) { return false; } RunningTaskInfo rti = TaskList.get(0); String tmp = rti.topActivity.getPackageName(); return tmp.equals(context.getPackageName()); } }