Reputation: 801
In my application i setup Up and Back navigation.
On up navigation previous activity
gets recreated, but on back navigation current activity
is finished.
Is possible on up navigation to finish current activity
but im not sure if is the best solution.
Want to know if is a normal practice that activity get recreated on up navigation and if finish()
; workaround is also a good solution to not recreate previous activity
.
Thanks
Upvotes: 1
Views: 188
Reputation: 2151
What I do in a lot of cases (not always) is call onBackPressed()
in the onOptionsItemSelected()
method.
Like so:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
This way the behaviour for both the back button and up navigation is identical. This is used in commercial apps. I am not sure if this is used in many other apps but it works for us.
Upvotes: 1