Show navigation Hide navigation

Implementing Descendant Navigation

Descendant navigation is navigation down the application's information hierarchy. This is described in Designing Effective Navigation and also covered in Android Design: Application Structure.

Descendant navigation is usually implemented using Intent objects and startActivity(), or by adding fragments to an activity using FragmentTransaction objects. This lesson covers other interesting cases that arise when implementing descendant navigation.

Implement Master/Detail Flows Across Handsets and Tablets

In a master/detail navigation flow, a master screen contains a list of items in a collection, and a detail screen shows detailed information about a specific item within that collection. Implementing navigation from the master screen to the detail screen is one form of descendant navigation.

Handset touchscreens are most suitable for displaying one screen at a time (either the master or the detail screen); this concern is further discussed in Planning for Multiple Touchscreen Sizes. Descendant navigation in this case is often implemented using an Intent that starts an activity representing the detail screen. On the other hand, tablet displays, especially when viewed in the landscape orientation, are best suited for showing multiple content panes at a time: the master on the left, and the detail to the right). Here, descendant navigation is usually implemented using a FragmentTransaction that adds, removes, or replaces the detail pane with new content.

The basics of implementing this pattern are described in the Implementing Adaptive UI Flows lesson of the Designing for Multiple Screens class. The class describes how to implement a master/detail flow using two activities on a handset and a single activity on a tablet.

Navigate into External Activities

There are cases where descending into your application's information hierarchy leads to activities from other applications. For example, when viewing the contact details screen for an entry in the phone address book, a child screen detailing recent posts by the contact on a social network may belong to a social networking application.

When launching another application's activity to allow the user to say, compose an email or pick a photo attachment, you generally don't want the user to return to this activity if they relaunch your application from the Launcher (the device home screen). It would be confusing if touching your application icon brought the user to a "compose email" screen.

To prevent this from occurring, simply add the FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET flag to the intent used to launch the external activity, like so:

Intent externalActivityIntent = new Intent(Intent.ACTION_PICK);
externalActivityIntent.setType("image/*");
externalActivityIntent.addFlags(
        Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(externalActivityIntent);