ActivityRecordperformClearTop(ActivityRecord newR,int launchFlags,int[] finishCount){// The task should be preserved for putting new activity in case the last activity is// finished if it is normal launch mode and not single top ("clear-task-top").
mReuseTask =true;
mTaskSupervisor.beginDeferResume();finalActivityRecord result;try{
result =clearTopActivities(newR, launchFlags, finishCount);}finally{
mTaskSupervisor.endDeferResume();
mReuseTask =false;}return result;}
privateActivityRecordclearTopActivities(ActivityRecord newR,int launchFlags,int[] finishCount){finalActivityRecord r =findActivityInHistory(newR.mActivityComponent, newR.mUserId);if(r ==null)returnnull;finalPooledPredicate f =PooledLambda.obtainPredicate((ActivityRecord ar,ActivityRecord boundaryActivity)->finishActivityAbove(ar, boundaryActivity, finishCount),PooledLambda.__(ActivityRecord.class), r);forAllActivities(f);
f.recycle();// Finally, if this is a normal launch mode (that is, not expecting onNewIntent()), then we// will finish the current instance of the activity so a new fresh one can be started.if(r.launchMode ==ActivityInfo.LAUNCH_MULTIPLE&&(launchFlags &Intent.FLAG_ACTIVITY_SINGLE_TOP)==0&&!ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)){if(!r.finishing){
r.finishIfPossible("clear-task-top",false/* oomAdj */);}}return r;}
privatestaticbooleanfinishActivityAbove(ActivityRecord r,ActivityRecord boundaryActivity,@NonNullint[] finishCount){// Stop operation once we reach the boundary activity.if(r == boundaryActivity)returntrue;if(!r.finishing &&!r.isTaskOverlay()){finalActivityOptions opts = r.getOptions();if(opts !=null){
r.clearOptionsAnimation();// TODO: Why is this updating the boundary activity vs. the current activity???
boundaryActivity.updateOptionsLocked(opts);}
finishCount[0]+=1;
r.finishIfPossible("clear-task-stack",false/* oomAdj */);}returnfalse;}