android 获取当前正在运行的activity

ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
Log.d("packageName", "pkg:"+cn.getPackageName());
Log.d("className", "cls:"+cn.getClassName());

加权限
<uses-permission android:name="android.permission.GET_TASKS"/>

你可能感兴趣的:(android 获取当前正在运行的activity)