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
@Override
public void changeCursor(Cursor cursor) {
+ if (mActivity.isFinishing() && cursor != null) {
+ cursor.close();
+ cursor = null;
+ }
if (cursor != mActivity.mAlbumCursor) {
mActivity.mAlbumCursor = cursor;
getColumnIndices(cursor);