Up vs Back

Ian Lake
2 min readMay 12, 2016

I’m sure you’ve read the Navigation with Back and Up article. It’s an older page, but it checks out. Yes, in many cases back and up go to the same screen (as they should if you have a linear flow through your app). No, that doesn’t mean they’re the same thing. In particularly, they’ll be vastly different things when following an implicit intent.

Here’s the good part: the same techniques and things you use for notifications (TaskStackBuilder, etc) are exactly the same things used to build the correct Up behavior. If you haven’t looked through the list of methods for AppCompatActivity, you’ll note it already does everything for you. You don’t need to handle Up specifically in onOptionsItemSelected() (it does that), you can customize it just like the notifications case through onCreateSupportNavigateUpTaskStack(), etc. etc.

The important thing is:

  1. Up does not leave your app.
  2. Up does not ever leave your app.

There is one part in navigating up that is of note when it comes to your task and back stack, as detailed on the Navigating Up implementation training: Up is not just finishing the current Activity, but starts or resumes the parent Activity. This means if you are using the standard launchMode (the default), then the parent Activity will be popped off the stack and a new instance will be created. If you are using the singleTop launchMode, then it’ll instead get a callback to onNewIntent().

Remember the fundamental goals of back and up are different. Back takes you exactly where you were (edit: within the current task stack), while Up takes you to a fixed place, no matter where you came from.

--

--