From 49dc798e43960ec8735de73e47b8c40b42c2a368 Mon Sep 17 00:00:00 2001 From: Andrii Kulian Date: Thu, 21 Mar 2019 19:01:57 -0700 Subject: [PATCH] Fix extra onStop when finishing after onCreate Sometimes onStop was called after finishing activity in onCreate. This is unexpected, as in this case the state should transition directly to onDestroy. One possible cause is getting a window visibility change to visible state before request for destruction from server. Such window visibility change would not trigger any callbacks on its own, but could set the state of client record to ON_START. Then when the following destruction request comes, it causes the activity to stop by looking at its previous "started" state. This CL does not allow transitioning to started state while doing window visibility update if activity wasn't stopped before. Bug: 127106719 Test: ActivityThreadTest Change-Id: I0239e02e4cdb335e2fbbc3b8817278e40bbcea1c --- core/java/android/app/ActivityThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 38006dc5b943b..92e20bd5472e8 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4521,7 +4521,7 @@ public final class ActivityThread extends ClientTransactionHandler { if (!show && !r.stopped) { performStopActivityInner(r, null /* stopInfo */, show, false /* saveState */, false /* finalStateRequest */, "handleWindowVisibility"); - } else if (show && r.stopped) { + } else if (show && r.getLifecycleState() == ON_STOP) { // If we are getting ready to gc after going to the background, well // we are back active so skip it. unscheduleGcIdler();