Search code examples
androidandroid-activityback-stack

Implementing "UP" button functionality


I'm creating an App with 3 different activities:

  • MainActivity (Root activity to start ActivtyA and ActivtyB)
  • ActivtyA
  • ActivtyB

ActivtyA can start a new intent of itself with different viewcontent to be loaded with the following flow:

 MainActivity  -->  ActivtyA (Content 1)   -->  ActivtyA (Content 2)

Now i want the user to be directed to MainActivity if he presses the "UP" button in the actionbar and to be directed to ActivtyA (Content 1) if he presses the "BACK" button.

I don't want to use NavUtils.navigateUpFromSameTask(this); because of its weird behaviour on Jelly Bean and also i can't solely rely on the parentActivity flag inside my AndroidManifest, because i have to support backward Android Honeycomb 3.0. Is there any good solution for my problem?


Solution

  • back button implementation is easy, just call finish()

    for up button implementation you can start MainActivity using the flag FLAG_ACTIVITY_CLEAR_TOP