I have a long ListView
that the user can scroll around before returning to the previous screen. When the user opens this ListView
again, I want the
Am posting this because I am surprised nobody had mentioned this.
After user clicks the back button he will return to the listview in the same state as he went out of it.
This code will override the "up" button to behave the same way as the back button so in the case of Listview -> Details -> Back to Listview (and no other options) this is the simplest code to maintain the scrollposition and the content in the listview.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return(true);
}
return(super.onOptionsItemSelected(item)); }
Caution: If you can go to another activity from the details activity the up button will return you back to that activity so you will have to manipulate the backbutton history in order for this to work.