clear all activities in the task :
/**
* Completely remove all activities associated with an existing task.
*/
void performClearTaskForReuse(boolean excludingTaskOverlay) {
mReuseTask = true;
mTaskSupervisor.beginDeferResume();
try {
removeActivities("clear-task-all", excludingTaskOverlay);
} finally {
mTaskSupervisor.endDeferResume();
mReuseTask = false;
}
}
/** Completely remove all activities associated with an existing task. */
void removeActivities(String reason, boolean excludingTaskOverlay) {
clearPinnedTaskIfNeed();
// Broken down into to cases to avoid object create due to capturing mStack.
if (getRootTask() == null) {
forAllActivities((r) -> {
if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
return;
}
// Task was restored from persistent storage.
r.takeFromHistory();
removeChild(r, reason);
});
} else {
// Finish or destroy apps from the bottom to ensure that all the other activity have
// been finished and the top task in another task gets resumed when a top activity is
// removed. Otherwise, shell transitions wouldn't run because there would be no event
// that sets the transition ready.
final boolean traverseTopToBottom = !mTransitionController.isShellTransitionsEnabled();
final ArrayList<ActivityRecord> finishingActivities = new ArrayList<>();
forAllActivities(r -> {
if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
return;
}
finishingActivities.add(r);
}, traverseTopToBottom);
for (int i = 0; i < finishingActivities.size(); i++) {
final ActivityRecord r = finishingActivities.get(i);
// Prevent the transition from being executed too early if the top activity is
// resumed but the mVisibleRequested of any other activity is true, the transition
// should wait until next activity resumed.
if (r.isState(RESUMED) || (r.isVisible()
&& !mDisplayContent.mAppTransition.containsTransitRequest(TRANSIT_CLOSE))) {
r.finishIfPossible(reason, false /* oomAdj */);
} else {
r.destroyIfPossible(reason);
}
}
}
}