«

Android getTopActivity的方法

时间:2024-3-2 19:42     作者:韩俊     分类: Android


使用如下方法可以获得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>

标签: android

热门推荐