Ancestral navigation is up the application's information hierarchy, where the top of the hierarchy (or root) is the application's home screen. This navigation concept is described in Designing Effective Navigation
Implement Up Navigation
When implementing ancestral navigation, all screens in your application that aren't the home screen should offer a means of navigating to the immediate parent screen in the hierarchy via the Up button in the action bar.
Regardless of how the current screen was reached, pressing this button should always take the user to the same screen in the hierarchy.
To implement Up, enable it in the action bar in your activity's onCreate()
method:
You should also handle android.R.id.home
in onOptionsItemSelected()
. This resource is the menu item ID for the Home (or Up) button. To ensure that a specific parent activity is shown, DO NOT simply call finish()
. Instead, use an intent such as the one described below.
When the current activity belongs to a task from a different application—for example if it was reached via an intent from another application—pressing Up should create a new task for the application with a synthesized back stack. This approach is described in Android Design: Navigation and the TaskStackBuilder
class reference.
The NavUtils
and TaskStackBuilder
classes in the Android Support Package provide helpers for implementing this behavior correctly. An example usage of these two helper classes is below:
Properly Handle the Application Home Screen
By default, the Home button in the action bar is interactive. Since it does not make much sense to navigate home—or up one level—while on the home screen, you should disable the button like so: