From f0502a3c9caa15b003575f5c91f4ae7431c38a42 Mon Sep 17 00:00:00 2001 From: Sriram Ramasubramanian Date: Tue, 2 Apr 2013 11:26:35 -0700 Subject: [PATCH] Bug 856767: Finalize cursors on about:home. [r=mfinkle] --HG-- extra : rebase_source : 9389663903676defaf2c4cfcd818abe4e60e801e --- .../android/base/widget/AboutHomeContent.java | 3 ++- mobile/android/base/widget/TopSitesView.java | 26 ++++++++----------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/mobile/android/base/widget/AboutHomeContent.java b/mobile/android/base/widget/AboutHomeContent.java index d10a827e95c..a1c9e2cc2ee 100644 --- a/mobile/android/base/widget/AboutHomeContent.java +++ b/mobile/android/base/widget/AboutHomeContent.java @@ -219,11 +219,12 @@ public class AboutHomeContent extends ScrollView * Reinflates and updates all components of this view. */ public void refresh() { + mTopSites.onDestroy(); + // We must remove the currently inflated view to allow for reinflation. removeAllViews(); inflate(); - mTopSites.refresh(); // Refresh all elements. update(AboutHomeContent.UpdateFlags.ALL); diff --git a/mobile/android/base/widget/TopSitesView.java b/mobile/android/base/widget/TopSitesView.java index 835b878fdae..5debd566c84 100644 --- a/mobile/android/base/widget/TopSitesView.java +++ b/mobile/android/base/widget/TopSitesView.java @@ -141,9 +141,15 @@ public class TopSitesView extends GridView { public void onDestroy() { if (mTopSitesAdapter != null) { - Cursor cursor = mTopSitesAdapter.getCursor(); - if (cursor != null && !cursor.isClosed()) - cursor.close(); + final Cursor cursor = mTopSitesAdapter.getCursor(); + + ThreadUtils.postToBackgroundThread(new Runnable() { + @Override + public void run() { + if (cursor != null && !cursor.isClosed()) + cursor.close(); + } + }); } } @@ -186,12 +192,9 @@ public class TopSitesView extends GridView { public void loadTopSites() { final ContentResolver resolver = mContext.getContentResolver(); - Cursor old = null; - if (mTopSitesAdapter != null) { - old = mTopSitesAdapter.getCursor(); - } + // Swap in the new cursor. - final Cursor oldCursor = old; + final Cursor oldCursor = (mTopSitesAdapter != null) ? mTopSitesAdapter.getCursor() : null; final Cursor newCursor = BrowserDB.getTopSites(resolver, mNumberOfTopSites); post(new Runnable() { @@ -342,13 +345,6 @@ public class TopSitesView extends GridView { mLoadCompleteCallback = callback; } - public void refresh() { - if (mTopSitesAdapter != null) - mTopSitesAdapter.notifyDataSetChanged(); - - setAdapter(mTopSitesAdapter); - } - private class TopSitesViewHolder { public TextView titleView = null; public ImageView thumbnailView = null;