currently I am using ListActivity. I use a cursor to get the data from SQL, and built the ListView according to the SQL query result. For every objects in my ListView, if I press that object (onListItemClick), it will change the value in the SQL that the cursor will read, and open a new intent.(Pressing on different object will change different value in the SQL table). To keep my ListView most updated, I use
//adapter is the SimpleCursorAdapter I use
protected void onListItemClick(ListView l, View view, int position, long id) {
super.onListItemClick(l, view, position, id);
//change the data in sql
...
//change the data end
adapter.changeCursor(dbAdapter.getResult(id));
adapter.notifyDataSetChanged();
//create intent here
//startActivity(intent)
}
The problem is, if I keep pressing the same object, leave the intent it create, it works fine. But once I press a different object after I leave the previous intent, my ListView becomes empty. For example, if I press object a, I enter intent a, and then I leave intent a, back to List View (ListView is fine now), then I press on object b, I enter the intent b. When I leave intent b, the ListView becomes empty. Does anyone has any idea about this problem? Thank you.
It sounds like some of your data is being destroyed. I think if you move your list creation code to onResume, your problem will solve itself as the list will be re-generated every time you come back, wheras in onCreate it is only done when the activity is first created.
A picture is worth a thousand words:
