Java tutorial
//package com.java2s; //License from project: Apache License import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; public class Main { public static boolean isTopActivy(Context context, String activityName) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cName = am.getRunningTasks(1).size() > 0 ? am.getRunningTasks(1).get(0).topActivity : null; if (null == cName) return false; return cName.getClassName().equals(activityName); } }