Skip to content Skip to sidebar Skip to footer

Activity Not Properly Managing Cursor.

I have an activity that populates a list and does some other things from a cursor. I get the cursor from a method that returns it based on a standard android SQLite query to my dat

Solution 1:

Try closing the cursor in the onPause() (cursor.close()). If you are using a SimpleCursorAdapter you should also detach the cursor from the adapter.

You can requery for the cursor in the onResume() method if you wish.

Solution 2:

Well, it turns out that Cursor.requery() is depreciated and I was getting the same error every time I tried to call it. startManagingCursor() was calling requery, as I suppose it should, and that in turn was causing my problems there... I'm not sure why requery is causing an error in this instance, I've used it successfully before.

I ended up rearranging some code, and putting my cursor = SQLHelper.getwhatevercursor() code into onResume() instead of onCreate, as onResume is called right after onCreate anyway. As recommended by Nikola I am also closing the cursors in onPause().

This seems to be working now...

Post a Comment for "Activity Not Properly Managing Cursor."