看到了不少人判断某个activity是否存在栈中是类似这样写的:
private boolean isExist(Class<?> activity) {
Intent intent = new Intent(this, activity);
ComponentName cmpName = intent.resolveActivity(getPackageManager());
boolean flag = false;
// 说明系统中存在这个activity
if (cmpName != null) {
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
//获取从栈顶开始往下查找的10个activity
List<ActivityManager.RunningTaskInfo> taskInfoList = am.getRunningTasks(10);
for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) {
// 说明它已经启动了
if (taskInfo.baseActivity.equals(cmpName)) {
//true 存在 falese 不存在
flag = true;
break;//跳出循环
}
}
}
return flag;
}
那么好使吗!!!taskInfo.baseActivity到底是哪个activity!!!
点进源码瞅一眼呐!!!
自我感觉下有没有问题吧......