需要加一个权限:
<uses-permission android:name="android.permission.GET_TASKS"/>
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTasks = manager .getRunningTasks(1); RunningTaskInfo cinfo = runningTasks.get(0); ComponentName component = cinfo.topActivity; Log.e("current activity is ", component.getClassName());
获得当前正在显示的activity的类名
时间: 2024-10-16 00:04:51