tags:

views:

43

answers:

2

Im performing certain database operations after which I attach Cursor to the SimpleCursorAdapter for display List on my ListActivity. If I close the cursor in finally block (or anywhere after the code below), nothing is displayed in the list

SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this, 
          R.layout.list_row, cursor,
          new String[] { Constants.KEY_TITLE }, new int[] { R.id.text1 });

If the cursor is not closed, Android throws exception when activity makes request to another activity or is passivated.

PS I tried closing cursor inside onPause(), but android complains before onPause is called.

+1  A: 

You have to leave open the cursor on your finally block.

You missed out to call in your activity.

startManagingCursor(cursor);

This will make sure the activity manages the Cursor for you.

Pentium10
A: 

That only solves part of the problem. When I startManagingCursor(cursor); and hit Menu key > menuActivity then > back key I get:

ERROR/Cursor(4047): Invalid statement in fillWindow()
taranfx