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:
- Launch into activity A, it contains two buttons: each taking you to activities B and C, respectively.
- Tap the button for activity B.
- Transition to activity B. it contains two buttons: each taking you to activities A and C, respectively.
- Tap the button for activity C.
- Transition to activity C.
- Tap the "up" button, you should be taken to activity B.
- On activity B now: tap the button for activity A.
- Transition to activity A.
- Tap the "up" button, you should be taken to activity B.
- On activity B Tap the "up" button, you should be taken to activity A.
- On activity A now: tap the button for activity C.
- Transition to activity C.
- Tap the "up" button, you should be taken to activity A.
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?
from all three of your activities add the following
when you press the up button on your app it will invoke
onOptionsItemSelected
with the id ofandroid.R.id.home
just catch that case and manually callonBackPressed()