Java tutorial
//package com.java2s; //License from project: Apache License import android.app.ActivityManager; import android.content.Context; import android.text.TextUtils; import java.util.List; public class Main { public static String getRunningActivityName(Context context, String packageName) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> processInfos = activityManager.getRunningTasks(10); for (ActivityManager.RunningTaskInfo taskInfo : processInfos) { if (taskInfo.topActivity != null) { if (TextUtils.equals(packageName, taskInfo.topActivity.getPackageName())) { return taskInfo.topActivity.getClassName(); } } } return null; } }