blob: 7d0063c016f27da2de74f1e98c0f281ba9f50498 [file] [log] [blame]
page.title=Implementing Descendant Navigation
parent.title=Implementing Effective Navigation
previous.title=Implementing Temporal Navigation
<div id="tb-wrapper">
<div id="tb">
<h2>This lesson teaches you to:</h2>
<li><a href="#master-detail">Implement Master/Detail Flows Across Handsets and Tablets</a></li>
<li><a href="#external-activities">Navigate into External Activities</a></li>
<h2>You should also read</h2>
<li><a href="{@docRoot}training/design-navigation/descendant-lateral.html">Providing Descendant and Lateral Navigation</a></li>
<li><a href="{@docRoot}design/patterns/app-structure.html">Android Design: App Structure</a></li>
<li><a href="{@docRoot}design/patterns/multi-pane-layouts.html">Android Design: Multi-pane Layouts</a></li>
<h2>Try it out</h2>
<div class="download-box">
<a href=""
class="button">Download the sample app</a>
<p class="filename"></p>
<p><em>Descendant navigation</em> is navigation down the application's information hierarchy. This is described in <a href="{@docRoot}training/design-navigation/descendant-lateral.html">Designing Effective Navigation</a> and also covered in <a href="{@docRoot}design/patterns/app-structure.html">Android Design: Application Structure</a>.</p>
<p>Descendant navigation is usually implemented using {@link android.content.Intent} objects and {@link android.content.Context#startActivity startActivity()}, or by adding fragments to an activity using {@link} objects. This lesson covers other interesting cases that arise when implementing descendant navigation.</p>
<h2 id="master-detail">Implement Master/Detail Flows Across Handsets and Tablets</h2>
<p>In a <em>master/detail</em> navigation flow, a <em>master</em> screen contains a list of items in a collection, and a <em>detail</em> 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.</p>
<p>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 <a href="{@docRoot}training/design-navigation/multiple-sizes.html">Planning for Multiple Touchscreen Sizes</a>. Descendant navigation in this case is often implemented using an {@link android.content.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 {@link} that adds, removes, or replaces the detail pane with new content.</p>
<p>The basics of implementing this pattern are described in the <a href="{@docRoot}training/multiscreen/adaptui.html">Implementing Adaptive UI Flows</a> lesson of the <em>Designing for Multiple Screens</em> class. The class describes how to implement a master/detail flow using two activities on a handset and a single activity on a tablet.</p>
<h2 id="external-activities">Navigate into External Activities</h2>
<p>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.</p>
<p>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.</p>
<p>To prevent this from occurring, simply add the {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET} flag to the intent used to launch the external activity, like so:</p>
Intent externalActivityIntent = new Intent(Intent.ACTION_PICK);