@@ -11,7 +11,7 @@ parent.link=activities.html
1111 <li>Fragments decompose application functionality and UI into reusable modules</li>
1212 <li>Add multiple fragments to a screen to avoid switching activities</li>
1313 <li>Fragments have their own lifecycle, state, and back stack</li>
14- <li>Fragments require API Level "Honeycomb" or greater</li>
14+ <li>Fragments require API Level 11 or greater</li>
1515 </ul>
1616
1717 <h2>In this document</h2>
@@ -49,16 +49,25 @@ parent.link=activities.html
4949 <h2>Related samples</h2>
5050 <ol>
5151 <li><a
52+ href="{@docRoot}resources/samples/HoneycombGallery/index.html">Honeycomb Gallery</a></li>
53+ <li><a
5254href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/index.html#Fragment">ApiDemos</a></li>
5355 </ol>
56+
57+ <h2>See also</h2>
58+ <ol>
59+ <li><a href="{@docRoot}guide/practices/tablets-and-handsets.html">Supporting Tablets
60+ and Handsets</a></li>
61+ </ol>
5462</div>
5563</div>
5664
5765<p>A {@link android.app.Fragment} represents a behavior or a portion of user interface in an
5866{@link android.app.Activity}. You can combine multiple fragments in a single activity to build a
5967multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a
6068modular section of an activity, which has its own lifecycle, receives its own input events, and
61- which you can add or remove while the activity is running.</p>
69+ which you can add or remove while the activity is running (sort of like a "sub activity" that
70+ you can reuse in different activities).</p>
6271
6372<p>A fragment must always be embedded in an activity and the fragment's lifecycle is directly
6473affected by the host activity's lifecycle. For example, when the activity is paused, so are all
@@ -69,14 +78,16 @@ manipulate each fragment independently, such as add or remove them. When you per
6978fragment transaction, you can also add it to a back stack that's managed by the
7079activity—each back stack entry in the activity is a record of the fragment transaction that
7180occurred. The back stack allows the user to reverse a fragment transaction (navigate backwards),
72- by pressing the BACK key .</p>
81+ by pressing the BACK button .</p>
7382
7483<p>When you add a fragment as a part of your activity layout, it lives in a {@link
75- android.view.ViewGroup} inside the activity's view hierarchy and defines its own layout of views.
84+ android.view.ViewGroup} inside the activity's view hierarchy and the fragment defines its own view
85+ layout.
7686You can insert a fragment into your activity layout by declaring the fragment in the activity's
7787layout file, as a {@code <fragment>} element, or from your application code by adding it to an
7888existing {@link android.view.ViewGroup}. However, a fragment is not required to be a part of the
79- activity layout; you may also use a fragment as an invisible worker for the activity.</p>
89+ activity layout; you may also use a fragment without its own UI as an invisible worker for the
90+ activity.</p>
8091
8192<p>This document describes how to build your application to use fragments, including
8293how fragments can maintain their state when added to the activity's back stack, share
@@ -86,9 +97,9 @@ bar, and more.</p>
8697
8798<h2 id="Design">Design Philosophy</h2>
8899
89- <p>Android introduced fragments in Android 3.0 (API Level "Honeycomb" ), primarily to support more
100+ <p>Android introduced fragments in Android 3.0 (API level 11 ), primarily to support more
90101dynamic and flexible UI designs on large screens, such as tablets. Because a
91- tablet's screen is much larger than that of a mobile phone , there's more room to combine and
102+ tablet's screen is much larger than that of a handset , there's more room to combine and
92103interchange UI components. Fragments allow such designs without the need for you to manage complex
93104changes to the view hierarchy. By dividing the layout of an activity into fragments, you become able
94105to modify the activity's appearance at runtime and preserve those changes in a back stack
@@ -99,28 +110,34 @@ left and another fragment to display an article on the right—both fragment
99110activity, side by side, and each fragment has its own set of lifecycle callback methods and handle
100111their own user input events. Thus, instead of using one activity to select an article and another
101112activity to read the article, the user can select an article and read it all within the same
102- activity, as illustrated in figure 1.</p>
113+ activity, as illustrated in the tablet layout in figure 1.</p>
114+
115+ <p>You should design each fragment as a modular and reusable activity component. That is, because
116+ each fragment defines its own layout and its own behavior with its own lifecycle callbacks, you can
117+ include one fragment in multiple activities, so you should design for reuse and avoid directly
118+ manipulating one fragment from another fragment. This is especially important because a modular
119+ fragment allows you to change your fragment combinations for different screen sizes. When designing
120+ your application to support both tablets and handsets, you can reuse your fragments in different
121+ layout configurations to optimize the user experience based on the available screen space. For
122+ example, on a handset, it might be necessary to separate fragments to provide a single-pane UI when
123+ more than one cannot fit within the same activity.</p>
103124
104125<img src="{@docRoot}images/fundamentals/fragments.png" alt="" />
105- <p class="img-caption"><strong>Figure 1.</strong> An example of how two UI modules that are
106- typically separated into two activities can be combined into one activity, using fragments.</p>
107-
108-
109- <p>A fragment should be a modular and reusable component in your application. That is, because the
110- fragment defines its own layout and its own behavior using its own lifecycle callbacks, you
111- can include one fragment in multiple activities. This is especially important because it allows you
112- to adapt your user experience to different screen sizes. For instance, you might include multiple
113- fragments in an activity only when the screen size is sufficiently large, and, when it is not,
114- launch separate activities that use different fragments.</p>
126+ <p class="img-caption"><strong>Figure 1.</strong> An example of how two UI modules defined by
127+ fragments can be combined into one activity for a tablet design, but separated for a
128+ handset design.</p>
115129
116130<p>For example—to continue with the news application example—the application can embed
117- two
118- fragments in <em>Activity A</em>, when running on an extra large screen (a tablet, for example).
119- However, on a normal-sized screen (a phone, for example),
120- there's not be enough room for both fragments, so <em>Activity A</em> includes only the fragment for
121- the list of articles, and when the user selects an article, it starts <em>Activity B</em>, which
122- includes the fragment to read the article. Thus, the application supports both design patterns
123- suggested in figure 1.</p>
131+ two fragments in <em>Activity A</em>, when running on a tablet-sized device. However, on a
132+ handset-sized screen, there's not be enough room for both fragments, so <em>Activity A</em> includes
133+ only the fragment for the list of articles, and when the user selects an article, it starts
134+ <em>Activity B</em>, which includes the second fragment to read the article. Thus, the application
135+ supports both tablets and handsets by reusing fragments in different combinations, as illustrated in
136+ figure 1.</p>
137+
138+ <p>For more information about designing your application with different fragment combinations for
139+ different screen configurations, see the guide to <a
140+ href="{@docRoot}guide/practices/tablets-and-handsets.html">Supporting Tablets and Handsets</a>.</p>
124141
125142
126143
0 commit comments