From ebb5c75344168397403edd74f8fc5e9603e41b13 Mon Sep 17 00:00:00 2001 From: vadimt Date: Fri, 18 Oct 2019 11:34:21 -0700 Subject: [PATCH] Fixing activity leak on config change If attachTo happens before the view is attached to window, ViewOnDrawExecutor hooks to the tree observer twice (second time from onViewAttachedToWindow). It only unhooks once. Since tree observer is global, this leads to leaking the activity, and besides, all old activities getting the events from the tree observer. Bug: 139137636 Change-Id: Ie2641b8f3614545052fe34ad6588b070c3b82a33 --- src/com/android/launcher3/util/ViewOnDrawExecutor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/util/ViewOnDrawExecutor.java b/src/com/android/launcher3/util/ViewOnDrawExecutor.java index 61ba4e5662..5a131c83f8 100644 --- a/src/com/android/launcher3/util/ViewOnDrawExecutor.java +++ b/src/com/android/launcher3/util/ViewOnDrawExecutor.java @@ -55,7 +55,9 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable, mLoadAnimationCompleted = true; } - attachObserver(); + if (mAttachedView.isAttachedToWindow()) { + attachObserver(); + } } private void attachObserver() {