The Android app design I'm working with calls for the "Up" button to behave the same way the "Back" button behaves, but I'm not sure how to make that happen.
I know that android:parentActivityName
must be specified for the "Up" button to be visible on an activity, but specifying a fixed parent activity doesn't really make sense for the activity. Imagine this scenario with activities A, B, and C:
If I were to specify android:parentActivityName
for each activity, it might make sense to have B and C's parent activity be A, but this means that each time we hit the "up" button from activities B or C, we land at activity A (and that's not always what is supposed to happen).
Does anybody have experience with this type of thing?
Here is a simple method to add a back arrow to other Activity to come back to MainActivity. To enter a new activity we create an Intent then start a new Activity using that intent instance using the startActivity method.
When you press the Back button, the current destination is popped off the top of the back stack, and you then navigate to the previous destination. The Up button appears in the app bar at the top of the screen.
from all three of your activities add the following
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; } return(super.onOptionsItemSelected(item)); }
when you press the up button on your app it will invoke onOptionsItemSelected
with the id of android.R.id.home
just catch that case and manually call onBackPressed()
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