判断某个activity是否存在栈堆中
作者:
CQ_TYL | 来源:发表于
2019-01-21 18:28 被阅读0次private boolean isExistMainActivity(Class<?> activity) {
Intent intent = new Intent(this, activity);
ComponentName cmpName = intent.resolveActivity(getPackageManager());
boolean flag = false;
if (cmpName != null) {// 说明系统中存在这个activity
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfoList = am.getRunningTasks(10);//获取从栈顶开始往下查找的10个activity
for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) {
if (taskInfo.baseActivity.equals(cmpName)) {// 说明它已经启动了
flag = true;
break;//跳出循环,优化效率
}
}
}
return flag;//true 存在 falese 不存在
}
本文标题:判断某个activity是否存在栈堆中
本文链接:https://www.haomeiwen.com/subject/ewhhjqtx.html
网友评论