android 如何判断当前进程在主页面

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xiaoheichuangtianya/article/details/84759136
private boolean isTopActivity(String packageName) {



System.out.println("**********************top packageName:"

+ packageName);

ActivityManager activityManager = (ActivityManager) this

.getSystemService(Context.ACTIVITY_SERVICE);



List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);

if (tasksInfo.size() > 0) {

System.out.println("*********************curr packageName:"

+ tasksInfo.get(0).topActivity.getPackageName());

// 应用程序位于堆栈的顶层

if (packageName.equals(tasksInfo.get(0).topActivity

.getPackageName())) {

return true;

}

}

return false;



}
展开阅读全文

没有更多推荐了,返回首页