/** * App started in VA may be removed in OverView screen, then AMS.removeTask * will be invoked, all data struct about the task in AMS are released, * while the client's process is still alive. So remove related data in VA * as well. A new TaskRecord will be recreated in `onActivityCreated` */ private void optimizeTasksLocked() { // noinspection deprecation ArrayList<ActivityManager.RecentTaskInfo> recentTask = new ArrayList<>(mAM.getRecentTasks(Integer.MAX_VALUE, ActivityManager.RECENT_WITH_EXCLUDED | ActivityManager.RECENT_IGNORE_UNAVAILABLE)); int N = mHistory.size(); while (N-- > 0) { TaskRecord task = mHistory.valueAt(N); ListIterator<ActivityManager.RecentTaskInfo> iterator = recentTask.listIterator(); boolean taskAlive = false; while (iterator.hasNext()) { ActivityManager.RecentTaskInfo info = iterator.next(); if (info.id == task.taskId) { taskAlive = true; iterator.remove(); break; } } if (!taskAlive) { mHistory.removeAt(N); } } }
public List<ActivityManager.RecentTaskInfo> loadRecentTask(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RecentTaskInfo> activityInfoList = am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE); return activityInfoList; }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); final List<RecentTaskInfo> recentTasks = activityManager.getRecentTasks(Integer.MAX_VALUE, ActivityManager.RECENT_IGNORE_UNAVAILABLE); RecentTaskInfo recentTaskInfo = null; for (int i = 0; i < recentTasks.size(); i++) { if (recentTasks.get(i).baseIntent.getComponent().getPackageName().equals(packageName)) { recentTaskInfo = recentTasks.get(i); break; } } if(recentTaskInfo != null && recentTaskInfo.id > -1) { activityManager.moveTaskToFront(recentTaskInfo.persistentId, ActivityManager.MOVE_TASK_WITH_HOME); return; } }
/** * App started in VA may be removed in OverView screen, then AMS.removeTask * will be invoked, all data struct about the task in AMS are released, * while the client's process is still alive. So remove related data in VA * as well. A new TaskRecord will be recreated in `onActivityCreated` */ private void optimizeTasksLocked() { // noinspection deprecation ArrayList<ActivityManager.RecentTaskInfo> recentTask = new ArrayList<>(mAM.getRecentTasks(Integer.MAX_VALUE, ActivityManager.RECENT_WITH_EXCLUDED | ActivityManager.RECENT_IGNORE_UNAVAILABLE)); int N = mHistory.size(); while (N-- > 0) { TaskRecord task = mHistory.valueAt(N); ListIterator<ActivityManager.RecentTaskInfo> iterator = recentTask.listIterator(); boolean taskAlive = false; while (iterator.hasNext()) { ActivityManager.RecentTaskInfo info = iterator.next(); if (info.id == task.taskId) { taskAlive = true; iterator.remove(); break; } } if (!taskAlive) { mHistory.removeAt(N); } } }
/** * App started in VA may be removed in OverView screen, then AMS.removeTask * will be invoked, all data struct about the task in AMS are released, * while the client's process is still alive. So remove related data in VA * as well. A new TaskRecord will be recreated in `onActivityCreated` */ private void optimizeTasksLocked() { // noinspection deprecation ArrayList<ActivityManager.RecentTaskInfo> recentTask = new ArrayList<>(mAM.getRecentTasks(Integer.MAX_VALUE, ActivityManager.RECENT_WITH_EXCLUDED | ActivityManager.RECENT_IGNORE_UNAVAILABLE)); int N = mHistory.size(); while (N-- > 0) { TaskRecord task = mHistory.valueAt(N); ListIterator<ActivityManager.RecentTaskInfo> iterator = recentTask.listIterator(); boolean taskAlive = false; while (iterator.hasNext()) { ActivityManager.RecentTaskInfo info = iterator.next(); if (info.id == task.taskId) { taskAlive = true; iterator.remove(); break; } } if (!taskAlive) { mHistory.removeAt(N); } } }
if (activityManager.getRecentTasks(2, 0).size() > 0) { if (activityManager.getRecentTasks(2, 0).get(0).id != GlobalVars.taskID) { activityManager.moveTaskToFront(GlobalVars.taskID, 0);
if (activityManager.getRecentTasks(2, 0).get(0).id != taskID) { activityManager.moveTaskToFront(taskID, 0);