首页 > 代码库 > 获得当前正在显示的activity的类名

获得当前正在显示的activity的类名

需要加一个权限: 

<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());