diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 36e906cf9a628..86c10d6310e1a 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -1844,9 +1844,14 @@ final class ActivityRecord extends ConfigurationContainer { final ActivityRecord next = getDisplay().topRunningActivity( true /* considerKeyguardState */); final boolean isVisible = visible || nowVisible; + // isNextNotYetVisible is to check if the next activity is invisible, or it has been + // requested to be invisible but its windows haven't reported as invisible. If so, it + // implied that the current finishing activity should be added into stopping list rather + // than destroy immediately. + final boolean isNextNotYetVisible = next != null && (!next.nowVisible || !next.visible); final ActivityStack stack = getActivityStack(); final boolean notFocusedStack = stack != mRootActivityContainer.getTopDisplayFocusedStack(); - if (isVisible && next != null && !next.nowVisible) { + if (isVisible && isNextNotYetVisible) { addToStopping(false /* scheduleIdle */, false /* idleDelayed */, "completeFinishing"); if (DEBUG_STATES) { diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 31babd04f31d6..b2b1e16e02e93 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -1032,6 +1032,7 @@ public class ActivityRecordTests extends ActivityTestsBase { // simulates finishing in non-focused stack in split-screen. final ActivityStack stack = new StackBuilder(mRootActivityContainer).build(); stack.getChildAt(0).getChildAt(0).nowVisible = true; + stack.getChildAt(0).getChildAt(0).visible = true; topActivity.completeFinishing("test");