本文实例讲述了Android获得当前正在显示的activity类名的方法。分享给大家供大家参考。具体实现方法如下:
首先需要加一个权限:
复制代码 代码如下:
<uses-permission android:name="android.permission.GET_TASKS"/>
Java代码如下:
复制代码 代码如下:
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());
List<RunningTaskInfo> runningTasks = manager .getRunningTasks(1);
RunningTaskInfo cinfo = runningTasks.get(0);
ComponentName component = cinfo.topActivity;
Log.e("current activity is ", component.getClassName());
希望本文所述对大家的Android程序设计有所帮助。