I'm population my listView using Cursor, but when I nav开发者_运维百科igate away from my activity and then return back my listview is empty. Here is my code:
@Override
public void onCreate(Bundle savedInstanceState) {
...
DBAdapter db = new DBAdapter(context);
db.open();
Cursor c = db.getAll();
db.close();
startManagingCursor(c);
String[] columns = new String[] { ... };
int[] to = new int[] { ... };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.list_item, c, columns, to);
this.setListAdapter(mAdapter);
...
}
I've seen here questions about saving position of Cursor, but not the Cursor itself. Probably I just missing something, shall I save my cursor (how can I do it?) or it's better(faster, cheaper) to create new cursor every time using my DBadapter?
Thanks
startManagingCursor()
makes your close()
call unnecessary. As long as you didnt get exceptions about not finalizing or closing your cursor you have done anything right.
精彩评论