From 9c17a4c11005877b65d841f4fbd810df89c7c206 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Mon, 30 Aug 2010 18:04:15 -0700 Subject: Fix bug 2918587 Infinite loop and memory leak in AdapterView Change-Id: Icb63b186c56c2d731003dc38a8ff7a93a69a94e7 --- core/java/android/widget/AdapterView.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'core/java/android/widget/AdapterView.java') diff --git a/core/java/android/widget/AdapterView.java b/core/java/android/widget/AdapterView.java index 10a87295ccf5..8fcc2e87a966 100644 --- a/core/java/android/widget/AdapterView.java +++ b/core/java/android/widget/AdapterView.java @@ -808,7 +808,6 @@ public abstract class AdapterView extends ViewGroup { mNextSelectedPosition = INVALID_POSITION; mNextSelectedRowId = INVALID_ROW_ID; mNeedSync = false; - checkSelectionChanged(); checkFocus(); requestLayout(); @@ -819,13 +818,21 @@ public abstract class AdapterView extends ViewGroup { } } - private class SelectionNotifier extends Handler implements Runnable { + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + removeCallbacks(mSelectionNotifier); + } + + private class SelectionNotifier implements Runnable { public void run() { if (mDataChanged) { // Data has changed between when this SelectionNotifier // was posted and now. We need to wait until the AdapterView // has been synched to the new data. - post(this); + if (getAdapter() != null) { + post(this); + } } else { fireOnSelected(); } @@ -842,7 +849,7 @@ public abstract class AdapterView extends ViewGroup { if (mSelectionNotifier == null) { mSelectionNotifier = new SelectionNotifier(); } - mSelectionNotifier.post(mSelectionNotifier); + post(mSelectionNotifier); } else { fireOnSelected(); } -- cgit v1.2.3