From 52127d13975e4255c6133f1753e62b4829655808 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Mon, 21 Nov 2022 04:20:07 +0000 Subject: [PATCH] Mark the task as reusable while clearing activities in the Task All activities above the task root activity in the Task were finished while starting an Activity that declared with android:clearTaskOnLaunch=true. In that case, the organizer removed the secondary TaskFragment since the TaskFragment was empty. The primary TaskFragment was also removed due to the finish-primary-with-secondary rule. Bug: 257559481 Test: repo steps on the bug Change-Id: I52c019a8c550d6402916f7ae4499fb7692ff04f1 --- services/core/java/com/android/server/wm/Task.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 825e9e070a3e1..d0a19b7ab5859 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -5200,7 +5200,16 @@ class Task extends TaskFragment { final Task task = taskTop.getTask(); // If ActivityOptions are moved out and need to be aborted or moved to taskTop. - final ActivityOptions topOptions = sResetTargetTaskHelper.process(task, forceReset); + final ActivityOptions topOptions; + + // Set the task to be reused, so the TaskFragment#mClearedTaskForReuse can be set if the + // embedded activities are finished while reset task. + mReuseTask = true; + try { + topOptions = sResetTargetTaskHelper.process(task, forceReset); + } finally { + mReuseTask = false; + } if (mChildren.contains(task)) { final ActivityRecord newTop = task.getTopNonFinishingActivity();