OSDN Git Service

am 5edd0cbd: Fix build.
[android-x86/packages-apps-Music.git] / src / com / android / music / AlbumBrowserActivity.java
index fa6eeb4..8fe222d 100644 (file)
@@ -157,11 +157,12 @@ public class AlbumBrowserActivity extends ListActivity
         mLastListPosCourse = lv.getFirstVisiblePosition();
         mLastListPosFine = lv.getChildAt(0).getTop();
         MusicUtils.unbindFromService(this);
-        if (!mAdapterSent) {
-            Cursor c = mAdapter.getCursor();
-            if (c != null) {
-                c.close();
-            }
+        // If we have an adapter and didn't send it off to another activity yet, we should
+        // close its cursor, which we do by assigning a null cursor to it. Doing this
+        // instead of closing the cursor directly keeps the framework from accessing
+        // the closed cursor later.
+        if (!mAdapterSent && mAdapter != null) {
+            mAdapter.changeCursor(null);
         }
         // Because we pass the adapter to the next activity, we need to make
         // sure it doesn't keep a reference to this activity. We can do this
@@ -629,6 +630,10 @@ public class AlbumBrowserActivity extends ListActivity
         
         @Override
         public void changeCursor(Cursor cursor) {
+            if (mActivity.isFinishing() && cursor != null) {
+                cursor.close();
+                cursor = null;
+            }
             if (cursor != mActivity.mAlbumCursor) {
                 mActivity.mAlbumCursor = cursor;
                 getColumnIndices(cursor);