From 505bd0d60d26811ac1e61d2c39a2d5a995d2254d Mon Sep 17 00:00:00 2001 From: Martin Wallgren Date: Wed, 13 Apr 2011 15:03:35 +0200 Subject: onDetachedFromWindow is called before onAttachedToWindow Multiple threads are adding messages about the current state of the views to the main looper. This can cause onDetachedFromWindow to be posted on the looper before onAttachedToWindow. This change will make sure to only dispatch onDetachedFromWindow if we have previously dispatched onAttachToWindow. Change-Id: Ibc7cbcafb098bc000d2ef5480d2110d3fff4d55a --- core/java/android/view/ViewRoot.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'core/java/android/view/ViewRoot.java') diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index ccaef40..afec1c3 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -176,6 +176,7 @@ public final class ViewRoot extends Handler implements ViewParent, private final Surface mSurface = new Surface(); boolean mAdded; + private boolean mAttached; boolean mAddedTouchMode; /*package*/ int mAddNesting; @@ -762,7 +763,10 @@ public final class ViewRoot extends Handler implements ViewParent, attachInfo.mKeepScreenOn = false; viewVisibilityChanged = false; mLastConfiguration.setTo(host.getResources().getConfiguration()); - host.dispatchAttachedToWindow(attachInfo, 0); + if (!mAttached) { + host.dispatchAttachedToWindow(attachInfo, 0); + mAttached = true; + } //Log.i(TAG, "Screen on initialized: " + attachInfo.mKeepScreenOn); } else { @@ -1743,8 +1747,9 @@ public final class ViewRoot extends Handler implements ViewParent, void dispatchDetachedFromWindow() { if (Config.LOGV) Log.v(TAG, "Detaching in " + this + " of " + mSurface); - if (mView != null) { + if (mView != null && mAttached) { mView.dispatchDetachedFromWindow(); + mAttached = false; } mView = null; -- cgit v1.1