From e8b165253d03d67b30850cedee15e1214a453cb4 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 14 Jul 2009 13:06:42 -0700 Subject: Fixes #1977685. Prevent crash when the soft keyboard is brought up. ViewRoot keeps a reference to the previously focused View and use this reference when trying to scroll the window to the focused rect. There situations however in which the previously focused view might have been removed from the view hierarchy. This happens on Home for instance when you trash an icon, or with ListView's items. This change ensures the previously focused view is still part of the view hierarchy. --- core/java/android/view/ViewRoot.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index 6bcb135f6633..eab3799a9059 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -1367,6 +1367,15 @@ public final class ViewRoot extends Handler implements ViewParent, // is non-null and we just want to scroll to whatever that // rectangle is). View focus = mRealFocusedView; + + // When in touch mode, focus points to the previously focused view, + // which may have been removed from the view hierarchy. The following + // line checks whether the view is still in the hierarchy + if (focus == null || focus.getParent() == null) { + mRealFocusedView = null; + return false; + } + if (focus != mLastScrolledFocus) { // If the focus has changed, then ignore any requests to scroll // to a rectangle; first we want to make sure the entire focus -- cgit v1.2.3-59-g8ed1b