I have a problem with my android app.
I have a ListView and this ListView get the data from a Database and I bind it via a SimpleCursorAdapter.
Now I have a button to add a new entry to the database, then a new intent is started and I create a new item and add it to the database. After adding it, I go to a new page.
Now I want to have the following:
When I get to the new page, and I press the back button, I don’t want to be forwarded to the create new item page, I want to skip it and go directly back to the ListView.
The other problem, is that the ListView should then display the new entry. It should refresh in some way.
How to realize this?
When you create your new Intent to add the item to the database, make sure you set the
Intent.FLAG_ACTIVITY_NO_HISTORYso that the new Intent is not kept in the history stackeg:
myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)When an adapters underlying data is changed and you want the change to reflect in your ListView, call the adapters
notifyDataSetChanged()method (in your case, on clicking the back button)eg:
myAdapter.notifyDataSetChanged()