获取当前活动的activity

打印出来的结果就是包路径加类名
代码:

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

List runningTasks = am.getRunningTasks(1);

RunningTaskInfo rti = runningTasks.get(0);
ComponentName component = rti.topActivity;

Log.i("tracy", component.getClassName());


记得要加个权限:

你可能感兴趣的:(android)