Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; import java.util.List; public class Main { public static String getTopActivityName(Context context) { if (context == null) { return ""; } String topActivityClassName = null; try { ActivityManager activityManager = (ActivityManager) (context .getSystemService(android.content.Context.ACTIVITY_SERVICE)); List<ActivityManager.RunningTaskInfo> runningTaskInfos = activityManager.getRunningTasks(1); if (runningTaskInfos != null) { ComponentName f = runningTaskInfos.get(0).topActivity; topActivityClassName = f.getClassName(); } } catch (Exception e) { } return topActivityClassName; } }