使用如下方法可以获得top activity 的name
public String getTopActivityPackageName(Context context) { String topActivityPackage = null; ActivityManager activityManager = (ActivityManager) (context .getSystemService(android.content.Context.ACTIVITY_SERVICE)); List<RunningTaskInfo> runningTaskInfos = activityManager .getRunningTasks(1); if (runningTaskInfos != null) { ComponentName f = runningTaskInfos.get(0).topActivity; topActivityPackage = f.getPackageName(); } return topActivityPackage; }
<p>版权声明:本文为博主原创文章,未经博主允许不得转载。</p>