I have a scenario where I am clicking on a ListFragment and spinning up a new Activity like below:
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(getActivity(), VenueBeerActivity.class);
Parcelable wrapped = Parcels.wrap(mAdapter.getItem(position));
intent.putExtra("venue", wrapped);
startActivity(intent);
}
This works fine and displays the new activity.
I've modified this activities manifest so it points back to its parent activity (in this case main activity)
However the problem I have is when the back button is pressed, it reloads the entire parent. The parent is a list and I don't want it to reload the users position. How can I prevent this?
As a note. The parent houses a Page Tab Strip.
I'm sure this is a relatively simple fix...
What do you mean by "back button"? Is it the up button in the toolbar? If that's the case, edit the onOptionsItemSelected
in your VenueBeerActivity
to:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
So when user press the Up button it will get the behavior of the back button in the navigation bar.
In the parent activity, set the android:launchMode
attribute to singleTop
. This would prevent the system from creating a new instance of parent when up button is pressed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With