概述
Android 如何获取最顶端的Top Activity, 见如下代码:
public static class TopActivityInfo {
public String packageName = "";
public String topActivityName = "";
}
private TopActivityInfo getTopActivityInfo() {
ActivityManager manager = ((ActivityManager)GlobalConfig.getContext().getSystemService(Context.ACTIVITY_SERVICE));
TopActivityInfo info = new TopActivityInfo();
if (Build.VERSION.SDK_INT >= 21) {
List<ActivityManager.RunningAppProcessInfo> pis = manager.getRunningAppProcesses();
ActivityManager.RunningAppProcessInfo topAppProcess = pis.get(0);
if (topAppProcess != null && topAppProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
info.packageName = topAppProcess.processName;
info.topActivityName = "";
}
} else {
//getRunningTasks() is deprecated since API Level 21 (Android 5.0)
List localList = manager.getRunningTasks(1);
ActivityManager.RunningTaskInfo localRunningTaskInfo = (ActivityManager.RunningTaskInfo)localList.get(0);
info.packageName = localRunningTaskInfo.topActivity.getPackageName();
info.topActivityName = localRunningTaskInfo.topActivity.getClassName();
}
return info;
}
我在另外一篇文章里面介绍了另外几种获取最顶端Top Activity的方法, 详见: http://blog.csdn.net/wangbaochu/article/details/50554406
最后
以上就是柔弱康乃馨为你收集整理的Android 如何获取最顶端的Top Activity的全部内容,希望文章能够帮你解决Android 如何获取最顶端的Top Activity所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复