blob: 6933a7afd6983de7671efb089bb83354da1c9978 [file] [log] [blame]
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Chet Haasea18a86b2010-09-07 13:20:00 -070019import android.animation.Animator;
Dianne Hackbornc68c9132011-07-29 01:25:18 -070020import android.content.ComponentCallbacks2;
Dianne Hackbornb1ad5972010-08-02 17:30:33 -070021import android.content.Context;
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070022import android.content.Intent;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070023import android.content.res.Configuration;
Dianne Hackbornbdd19bc2010-11-10 23:27:54 -080024import android.content.res.Resources;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070025import android.os.Bundle;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070026import android.os.Parcel;
27import android.os.Parcelable;
Dianne Hackbornb7a2e472010-08-12 16:20:42 -070028import android.util.AndroidRuntimeException;
Dianne Hackborn3e82ba12013-07-16 13:23:55 -070029import android.util.ArrayMap;
Dianne Hackbornba51c3d2010-05-05 18:49:48 -070030import android.util.AttributeSet;
Dianne Hackborna2ea7472010-12-20 12:10:01 -080031import android.util.DebugUtils;
Dianne Hackborn03fcc332012-05-15 12:49:40 -070032import android.util.Log;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070033import android.util.SparseArray;
Dianne Hackborn5ddd1272010-06-12 10:15:28 -070034import android.view.ContextMenu;
Adam Powellf0f5fff2011-08-01 13:42:50 -070035import android.view.ContextMenu.ContextMenuInfo;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070036import android.view.LayoutInflater;
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -070037import android.view.Menu;
38import android.view.MenuInflater;
39import android.view.MenuItem;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070040import android.view.View;
Dianne Hackborn5ddd1272010-06-12 10:15:28 -070041import android.view.View.OnCreateContextMenuListener;
Adam Powellf0f5fff2011-08-01 13:42:50 -070042import android.view.ViewGroup;
Dianne Hackborn5ddd1272010-06-12 10:15:28 -070043import android.widget.AdapterView;
Dianne Hackborn2dedce62010-04-15 14:45:25 -070044
Dianne Hackborn625ac272010-09-17 18:29:22 -070045import java.io.FileDescriptor;
46import java.io.PrintWriter;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070047
48final class FragmentState implements Parcelable {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070049 final String mClassName;
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070050 final int mIndex;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070051 final boolean mFromLayout;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070052 final int mFragmentId;
53 final int mContainerId;
54 final String mTag;
55 final boolean mRetainInstance;
Dianne Hackborn16f6e892011-04-15 19:00:20 -070056 final boolean mDetached;
Dianne Hackbornb7a2e472010-08-12 16:20:42 -070057 final Bundle mArguments;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070058
59 Bundle mSavedFragmentState;
60
61 Fragment mInstance;
62
63 public FragmentState(Fragment frag) {
64 mClassName = frag.getClass().getName();
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070065 mIndex = frag.mIndex;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070066 mFromLayout = frag.mFromLayout;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070067 mFragmentId = frag.mFragmentId;
68 mContainerId = frag.mContainerId;
69 mTag = frag.mTag;
70 mRetainInstance = frag.mRetainInstance;
Dianne Hackborn16f6e892011-04-15 19:00:20 -070071 mDetached = frag.mDetached;
Dianne Hackbornb7a2e472010-08-12 16:20:42 -070072 mArguments = frag.mArguments;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070073 }
74
75 public FragmentState(Parcel in) {
76 mClassName = in.readString();
Dianne Hackborn6e8304e2010-05-14 00:42:53 -070077 mIndex = in.readInt();
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070078 mFromLayout = in.readInt() != 0;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070079 mFragmentId = in.readInt();
80 mContainerId = in.readInt();
81 mTag = in.readString();
82 mRetainInstance = in.readInt() != 0;
Dianne Hackborn16f6e892011-04-15 19:00:20 -070083 mDetached = in.readInt() != 0;
Dianne Hackbornb7a2e472010-08-12 16:20:42 -070084 mArguments = in.readBundle();
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070085 mSavedFragmentState = in.readBundle();
86 }
87
Dianne Hackborn62bea2f2012-09-04 18:48:15 -070088 public Fragment instantiate(Activity activity, Fragment parent) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070089 if (mInstance != null) {
90 return mInstance;
91 }
92
Dianne Hackborn51642462010-10-28 10:32:37 -070093 if (mArguments != null) {
94 mArguments.setClassLoader(activity.getClassLoader());
95 }
96
Dianne Hackbornb7a2e472010-08-12 16:20:42 -070097 mInstance = Fragment.instantiate(activity, mClassName, mArguments);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -070098
99 if (mSavedFragmentState != null) {
100 mSavedFragmentState.setClassLoader(activity.getClassLoader());
101 mInstance.mSavedFragmentState = mSavedFragmentState;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700102 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700103 mInstance.setIndex(mIndex, parent);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700104 mInstance.mFromLayout = mFromLayout;
Dianne Hackborn352cc982011-01-04 11:34:18 -0800105 mInstance.mRestored = true;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700106 mInstance.mFragmentId = mFragmentId;
107 mInstance.mContainerId = mContainerId;
108 mInstance.mTag = mTag;
109 mInstance.mRetainInstance = mRetainInstance;
Dianne Hackborn16f6e892011-04-15 19:00:20 -0700110 mInstance.mDetached = mDetached;
Dianne Hackborn3e449ce2010-09-11 20:52:31 -0700111 mInstance.mFragmentManager = activity.mFragments;
Dianne Hackborn03fcc332012-05-15 12:49:40 -0700112 if (FragmentManagerImpl.DEBUG) Log.v(FragmentManagerImpl.TAG,
113 "Instantiated fragment " + mInstance);
114
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700115 return mInstance;
116 }
117
118 public int describeContents() {
119 return 0;
120 }
121
122 public void writeToParcel(Parcel dest, int flags) {
123 dest.writeString(mClassName);
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700124 dest.writeInt(mIndex);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700125 dest.writeInt(mFromLayout ? 1 : 0);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700126 dest.writeInt(mFragmentId);
127 dest.writeInt(mContainerId);
128 dest.writeString(mTag);
129 dest.writeInt(mRetainInstance ? 1 : 0);
Dianne Hackborn16f6e892011-04-15 19:00:20 -0700130 dest.writeInt(mDetached ? 1 : 0);
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700131 dest.writeBundle(mArguments);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700132 dest.writeBundle(mSavedFragmentState);
133 }
134
135 public static final Parcelable.Creator<FragmentState> CREATOR
136 = new Parcelable.Creator<FragmentState>() {
137 public FragmentState createFromParcel(Parcel in) {
138 return new FragmentState(in);
139 }
140
141 public FragmentState[] newArray(int size) {
142 return new FragmentState[size];
143 }
144 };
145}
146
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700147/**
148 * A Fragment is a piece of an application's user interface or behavior
Dianne Hackborn291905e2010-08-17 15:17:15 -0700149 * that can be placed in an {@link Activity}. Interaction with fragments
150 * is done through {@link FragmentManager}, which can be obtained via
151 * {@link Activity#getFragmentManager() Activity.getFragmentManager()} and
152 * {@link Fragment#getFragmentManager() Fragment.getFragmentManager()}.
153 *
154 * <p>The Fragment class can be used many ways to achieve a wide variety of
felipeal1b4e4b62012-02-27 12:09:13 -0800155 * results. In its core, it represents a particular operation or interface
Dianne Hackborn291905e2010-08-17 15:17:15 -0700156 * that is running within a larger {@link Activity}. A Fragment is closely
157 * tied to the Activity it is in, and can not be used apart from one. Though
158 * Fragment defines its own lifecycle, that lifecycle is dependent on its
159 * activity: if the activity is stopped, no fragments inside of it can be
160 * started; when the activity is destroyed, all fragments will be destroyed.
161 *
162 * <p>All subclasses of Fragment must include a public empty constructor.
163 * The framework will often re-instantiate a fragment class when needed,
164 * in particular during state restore, and needs to be able to find this
165 * constructor to instantiate it. If the empty constructor is not available,
166 * a runtime exception will occur in some cases during state restore.
167 *
168 * <p>Topics covered here:
169 * <ol>
Dianne Hackbornf9dd34f2011-04-19 18:44:03 -0700170 * <li><a href="#OlderPlatforms">Older Platforms</a>
Dianne Hackborn291905e2010-08-17 15:17:15 -0700171 * <li><a href="#Lifecycle">Lifecycle</a>
172 * <li><a href="#Layout">Layout</a>
173 * <li><a href="#BackStack">Back Stack</a>
174 * </ol>
175 *
Joe Fernandezb54e7a32011-10-03 15:09:50 -0700176 * <div class="special reference">
177 * <h3>Developer Guides</h3>
178 * <p>For more information about using fragments, read the
179 * <a href="{@docRoot}guide/topics/fundamentals/fragments.html">Fragments</a> developer guide.</p>
180 * </div>
181 *
Dianne Hackbornf9dd34f2011-04-19 18:44:03 -0700182 * <a name="OlderPlatforms"></a>
183 * <h3>Older Platforms</h3>
184 *
185 * While the Fragment API was introduced in
186 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, a version of the API
Dianne Hackborn7871bad2011-12-12 15:19:26 -0800187 * at is also available for use on older platforms through
188 * {@link android.support.v4.app.FragmentActivity}. See the blog post
Dianne Hackbornf9dd34f2011-04-19 18:44:03 -0700189 * <a href="http://android-developers.blogspot.com/2011/03/fragments-for-all.html">
190 * Fragments For All</a> for more details.
191 *
Dianne Hackborn291905e2010-08-17 15:17:15 -0700192 * <a name="Lifecycle"></a>
193 * <h3>Lifecycle</h3>
194 *
195 * <p>Though a Fragment's lifecycle is tied to its owning activity, it has
196 * its own wrinkle on the standard activity lifecycle. It includes basic
197 * activity lifecycle methods such as {@link #onResume}, but also important
198 * are methods related to interactions with the activity and UI generation.
199 *
200 * <p>The core series of lifecycle methods that are called to bring a fragment
201 * up to resumed state (interacting with the user) are:
202 *
203 * <ol>
204 * <li> {@link #onAttach} called once the fragment is associated with its activity.
205 * <li> {@link #onCreate} called to do initial creation of the fragment.
206 * <li> {@link #onCreateView} creates and returns the view hierarchy associated
207 * with the fragment.
208 * <li> {@link #onActivityCreated} tells the fragment that its activity has
Quddus Chong37900012012-04-11 11:57:50 -0700209 * completed its own {@link Activity#onCreate Activity.onCreate()}.
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700210 * <li> {@link #onViewStateRestored} tells the fragment that all of the saved
211 * state of its view hierarchy has been restored.
Dianne Hackborn291905e2010-08-17 15:17:15 -0700212 * <li> {@link #onStart} makes the fragment visible to the user (based on its
213 * containing activity being started).
214 * <li> {@link #onResume} makes the fragment interacting with the user (based on its
215 * containing activity being resumed).
216 * </ol>
217 *
218 * <p>As a fragment is no longer being used, it goes through a reverse
219 * series of callbacks:
220 *
221 * <ol>
222 * <li> {@link #onPause} fragment is no longer interacting with the user either
223 * because its activity is being paused or a fragment operation is modifying it
224 * in the activity.
225 * <li> {@link #onStop} fragment is no longer visible to the user either
226 * because its activity is being stopped or a fragment operation is modifying it
227 * in the activity.
228 * <li> {@link #onDestroyView} allows the fragment to clean up resources
229 * associated with its View.
230 * <li> {@link #onDestroy} called to do final cleanup of the fragment's state.
231 * <li> {@link #onDetach} called immediately prior to the fragment no longer
232 * being associated with its activity.
233 * </ol>
234 *
235 * <a name="Layout"></a>
236 * <h3>Layout</h3>
237 *
238 * <p>Fragments can be used as part of your application's layout, allowing
239 * you to better modularize your code and more easily adjust your user
240 * interface to the screen it is running on. As an example, we can look
241 * at a simple program consisting of a list of items, and display of the
242 * details of each item.</p>
243 *
244 * <p>An activity's layout XML can include <code>&lt;fragment&gt;</code> tags
245 * to embed fragment instances inside of the layout. For example, here is
Dianne Hackborn625ac272010-09-17 18:29:22 -0700246 * a simple layout that embeds one fragment:</p>
Dianne Hackborn291905e2010-08-17 15:17:15 -0700247 *
248 * {@sample development/samples/ApiDemos/res/layout/fragment_layout.xml layout}
249 *
250 * <p>The layout is installed in the activity in the normal way:</p>
251 *
252 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
253 * main}
254 *
Dianne Hackborn87121ac2011-01-04 17:26:23 -0800255 * <p>The titles fragment, showing a list of titles, is fairly simple, relying
Dianne Hackborn291905e2010-08-17 15:17:15 -0700256 * on {@link ListFragment} for most of its work. Note the implementation of
Dianne Hackborn87121ac2011-01-04 17:26:23 -0800257 * clicking an item: depending on the current activity's layout, it can either
258 * create and display a new fragment to show the details in-place (more about
Ben Dodson542f2402011-06-14 16:40:23 -0700259 * this later), or start a new activity to show the details.</p>
Dianne Hackborn291905e2010-08-17 15:17:15 -0700260 *
261 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
262 * titles}
263 *
Ben Dodson542f2402011-06-14 16:40:23 -0700264 * <p>The details fragment showing the contents of a selected item just
Dianne Hackborn291905e2010-08-17 15:17:15 -0700265 * displays a string of text based on an index of a string array built in to
266 * the app:</p>
267 *
268 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
269 * details}
270 *
271 * <p>In this case when the user clicks on a title, there is no details
Ben Dodson542f2402011-06-14 16:40:23 -0700272 * container in the current activity, so the titles fragment's click code will
Dianne Hackborn291905e2010-08-17 15:17:15 -0700273 * launch a new activity to display the details fragment:</p>
274 *
275 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
276 * details_activity}
277 *
278 * <p>However the screen may be large enough to show both the list of titles
279 * and details about the currently selected title. To use such a layout on
280 * a landscape screen, this alternative layout can be placed under layout-land:</p>
281 *
282 * {@sample development/samples/ApiDemos/res/layout-land/fragment_layout.xml layout}
283 *
Dianne Hackborn87121ac2011-01-04 17:26:23 -0800284 * <p>Note how the prior code will adjust to this alternative UI flow: the titles
285 * fragment will now embed the details fragment inside of this activity, and the
286 * details activity will finish itself if it is running in a configuration
287 * where the details can be shown in-place.
Dianne Hackborn291905e2010-08-17 15:17:15 -0700288 *
Dianne Hackborn625ac272010-09-17 18:29:22 -0700289 * <p>When a configuration change causes the activity hosting these fragments
290 * to restart, its new instance may use a different layout that doesn't
291 * include the same fragments as the previous layout. In this case all of
292 * the previous fragments will still be instantiated and running in the new
Dianne Hackborn87121ac2011-01-04 17:26:23 -0800293 * instance. However, any that are no longer associated with a &lt;fragment&gt;
294 * tag in the view hierarchy will not have their content view created
295 * and will return false from {@link #isInLayout}. (The code here also shows
296 * how you can determine if a fragment placed in a container is no longer
297 * running in a layout with that container and avoid creating its view hierarchy
298 * in that case.)
Dianne Hackborn625ac272010-09-17 18:29:22 -0700299 *
300 * <p>The attributes of the &lt;fragment&gt; tag are used to control the
Dianne Hackborn87121ac2011-01-04 17:26:23 -0800301 * LayoutParams provided when attaching the fragment's view to the parent
302 * container. They can also be parsed by the fragment in {@link #onInflate}
Dianne Hackborn625ac272010-09-17 18:29:22 -0700303 * as parameters.
304 *
305 * <p>The fragment being instantiated must have some kind of unique identifier
306 * so that it can be re-associated with a previous instance if the parent
307 * activity needs to be destroyed and recreated. This can be provided these
308 * ways:
309 *
310 * <ul>
311 * <li>If nothing is explicitly supplied, the view ID of the container will
312 * be used.
313 * <li><code>android:tag</code> can be used in &lt;fragment&gt; to provide
314 * a specific tag name for the fragment.
315 * <li><code>android:id</code> can be used in &lt;fragment&gt; to provide
316 * a specific identifier for the fragment.
317 * </ul>
318 *
Dianne Hackborn291905e2010-08-17 15:17:15 -0700319 * <a name="BackStack"></a>
320 * <h3>Back Stack</h3>
321 *
322 * <p>The transaction in which fragments are modified can be placed on an
323 * internal back-stack of the owning activity. When the user presses back
324 * in the activity, any transactions on the back stack are popped off before
325 * the activity itself is finished.
326 *
327 * <p>For example, consider this simple fragment that is instantiated with
328 * an integer argument and displays that in a TextView in its UI:</p>
329 *
330 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentStack.java
331 * fragment}
332 *
333 * <p>A function that creates a new instance of the fragment, replacing
334 * whatever current fragment instance is being shown and pushing that change
335 * on to the back stack could be written as:
336 *
337 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentStack.java
338 * add_stack}
339 *
340 * <p>After each call to this function, a new entry is on the stack, and
341 * pressing back will pop it to return the user to whatever previous state
342 * the activity UI was in.
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700343 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700344public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListener {
Dianne Hackborn3e82ba12013-07-16 13:23:55 -0700345 private static final ArrayMap<String, Class<?>> sClassMap =
346 new ArrayMap<String, Class<?>>();
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700347
Adam Powell635c60a2011-10-26 10:22:16 -0700348 static final int INVALID_STATE = -1; // Invalid state used as a null value.
Dianne Hackbornc8017682010-07-06 13:34:38 -0700349 static final int INITIALIZING = 0; // Not yet created.
350 static final int CREATED = 1; // Created.
351 static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
Dianne Hackborn16f6e892011-04-15 19:00:20 -0700352 static final int STOPPED = 3; // Fully created, not started.
353 static final int STARTED = 4; // Created and started, not resumed.
354 static final int RESUMED = 5; // Created started and resumed.
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700355
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700356 int mState = INITIALIZING;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700357
Dianne Hackbornd173fa32010-12-23 13:58:22 -0800358 // Non-null if the fragment's view hierarchy is currently animating away,
359 // meaning we need to wait a bit on completely destroying it. This is the
360 // animation that is running.
361 Animator mAnimatingAway;
362
363 // If mAnimatingAway != null, this is the state we should move to once the
364 // animation is done.
365 int mStateAfterAnimating;
366
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700367 // When instantiated from saved state, this is the saved state.
368 Bundle mSavedFragmentState;
369 SparseArray<Parcelable> mSavedViewState;
370
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700371 // Index into active fragment array.
372 int mIndex = -1;
373
374 // Internal unique name for this fragment;
375 String mWho;
376
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700377 // Construction arguments;
378 Bundle mArguments;
379
Dianne Hackborndef15372010-08-15 12:43:52 -0700380 // Target fragment.
381 Fragment mTarget;
382
Dianne Hackbornf9302322011-06-14 18:36:14 -0700383 // For use when retaining a fragment: this is the index of the last mTarget.
384 int mTargetIndex = -1;
385
Dianne Hackborndef15372010-08-15 12:43:52 -0700386 // Target request code.
387 int mTargetRequestCode;
388
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700389 // True if the fragment is in the list of added fragments.
390 boolean mAdded;
391
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -0800392 // If set this fragment is being removed from its activity.
393 boolean mRemoving;
394
Dianne Hackborn2707d602010-07-09 18:01:20 -0700395 // True if the fragment is in the resumed state.
396 boolean mResumed;
397
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700398 // Set to true if this fragment was instantiated from a layout file.
399 boolean mFromLayout;
400
Dianne Hackborn625ac272010-09-17 18:29:22 -0700401 // Set to true when the view has actually been inflated in its layout.
402 boolean mInLayout;
403
Dianne Hackborn352cc982011-01-04 11:34:18 -0800404 // True if this fragment has been restored from previously saved state.
405 boolean mRestored;
406
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700407 // Number of active back stack entries this fragment is in.
Dianne Hackbornf121be72010-05-06 14:10:32 -0700408 int mBackStackNesting;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700409
Dianne Hackborn3e449ce2010-09-11 20:52:31 -0700410 // The fragment manager we are associated with. Set as soon as the
411 // fragment is used in a transaction; cleared after it has been removed
412 // from all transactions.
Adam Powell635c60a2011-10-26 10:22:16 -0700413 FragmentManagerImpl mFragmentManager;
Dianne Hackborn3e449ce2010-09-11 20:52:31 -0700414
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700415 // Activity this fragment is attached to.
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700416 Activity mActivity;
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700417
418 // Private fragment manager for child fragments inside of this one.
419 FragmentManagerImpl mChildFragmentManager;
420
421 // If this Fragment is contained in another Fragment, this is that container.
422 Fragment mParentFragment;
423
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700424 // The optional identifier for this fragment -- either the container ID if it
425 // was dynamically added to the view hierarchy, or the ID supplied in
426 // layout.
427 int mFragmentId;
428
429 // When a fragment is being dynamically added to the view hierarchy, this
430 // is the identifier of the parent container it is being added to.
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700431 int mContainerId;
432
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700433 // The optional named tag for this fragment -- usually used to find
434 // fragments that are not part of the layout.
435 String mTag;
436
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700437 // Set to true when the app has requested that this fragment be hidden
438 // from the user.
439 boolean mHidden;
440
Dianne Hackborn16f6e892011-04-15 19:00:20 -0700441 // Set to true when the app has requested that this fragment be detached.
442 boolean mDetached;
443
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700444 // If set this fragment would like its instance retained across
445 // configuration changes.
446 boolean mRetainInstance;
447
448 // If set this fragment is being retained across the current config change.
449 boolean mRetaining;
450
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700451 // If set this fragment has menu items to contribute.
452 boolean mHasMenu;
Dianne Hackborn6c285972011-08-29 16:53:49 -0700453
454 // Set to true to allow the fragment's menu to be shown.
455 boolean mMenuVisible = true;
456
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700457 // Used to verify that subclasses call through to super class.
458 boolean mCalled;
459
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700460 // If app has requested a specific animation, this is the one to use.
461 int mNextAnim;
462
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700463 // The parent container of the fragment after dynamically added to UI.
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700464 ViewGroup mContainer;
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700465
466 // The View generated for this fragment.
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700467 View mView;
468
Adam Powell635c60a2011-10-26 10:22:16 -0700469 // Whether this fragment should defer starting until after other fragments
470 // have been started and their loaders are finished.
471 boolean mDeferStart;
472
Adam Powell78fed9b2011-11-07 10:45:34 -0800473 // Hint provided by the app that this fragment is currently visible to the user.
474 boolean mUserVisibleHint = true;
475
Dianne Hackborn4911b782010-07-15 12:54:39 -0700476 LoaderManagerImpl mLoaderManager;
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -0700477 boolean mLoadersStarted;
Dianne Hackborn5e0d5952010-08-05 13:45:35 -0700478 boolean mCheckedForLoaderManager;
Dianne Hackbornc8017682010-07-06 13:34:38 -0700479
480 /**
Dianne Hackbornb46ed762011-06-02 18:33:15 -0700481 * State information that has been retrieved from a fragment instance
482 * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
483 * FragmentManager.saveFragmentInstanceState}.
484 */
485 public static class SavedState implements Parcelable {
486 final Bundle mState;
487
488 SavedState(Bundle state) {
489 mState = state;
490 }
491
492 SavedState(Parcel in, ClassLoader loader) {
493 mState = in.readBundle();
494 if (loader != null && mState != null) {
495 mState.setClassLoader(loader);
496 }
497 }
498
499 @Override
500 public int describeContents() {
501 return 0;
502 }
503
504 @Override
505 public void writeToParcel(Parcel dest, int flags) {
506 dest.writeBundle(mState);
507 }
508
509 public static final Parcelable.ClassLoaderCreator<SavedState> CREATOR
510 = new Parcelable.ClassLoaderCreator<SavedState>() {
511 public SavedState createFromParcel(Parcel in) {
512 return new SavedState(in, null);
513 }
514
515 public SavedState createFromParcel(Parcel in, ClassLoader loader) {
516 return new SavedState(in, loader);
517 }
518
519 public SavedState[] newArray(int size) {
520 return new SavedState[size];
521 }
522 };
523 }
524
525 /**
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700526 * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
527 * there is an instantiation failure.
528 */
529 static public class InstantiationException extends AndroidRuntimeException {
530 public InstantiationException(String msg, Exception cause) {
531 super(msg, cause);
532 }
533 }
534
535 /**
Dianne Hackborn291905e2010-08-17 15:17:15 -0700536 * Default constructor. <strong>Every</strong> fragment must have an
Dianne Hackbornc8017682010-07-06 13:34:38 -0700537 * empty constructor, so it can be instantiated when restoring its
538 * activity's state. It is strongly recommended that subclasses do not
539 * have other constructors with parameters, since these constructors
540 * will not be called when the fragment is re-instantiated; instead,
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700541 * arguments can be supplied by the caller with {@link #setArguments}
542 * and later retrieved by the Fragment with {@link #getArguments}.
543 *
Dianne Hackborn291905e2010-08-17 15:17:15 -0700544 * <p>Applications should generally not implement a constructor. The
545 * first place application code an run where the fragment is ready to
546 * be used is in {@link #onAttach(Activity)}, the point where the fragment
547 * is actually associated with its activity. Some applications may also
548 * want to implement {@link #onInflate} to retrieve attributes from a
549 * layout resource, though should take care here because this happens for
550 * the fragment is attached to its activity.
Dianne Hackbornc8017682010-07-06 13:34:38 -0700551 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700552 public Fragment() {
553 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700554
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700555 /**
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700556 * Like {@link #instantiate(Context, String, Bundle)} but with a null
557 * argument Bundle.
558 */
559 public static Fragment instantiate(Context context, String fname) {
560 return instantiate(context, fname, null);
561 }
562
563 /**
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700564 * Create a new instance of a Fragment with the given class name. This is
565 * the same as calling its empty constructor.
566 *
567 * @param context The calling context being used to instantiate the fragment.
568 * This is currently just used to get its ClassLoader.
569 * @param fname The class name of the fragment to instantiate.
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700570 * @param args Bundle of arguments to supply to the fragment, which it
571 * can retrieve with {@link #getArguments()}. May be null.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700572 * @return Returns a new fragment instance.
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700573 * @throws InstantiationException If there is a failure in instantiating
574 * the given fragment class. This is a runtime exception; it is not
575 * normally expected to happen.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700576 */
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700577 public static Fragment instantiate(Context context, String fname, Bundle args) {
578 try {
579 Class<?> clazz = sClassMap.get(fname);
580 if (clazz == null) {
581 // Class not found in the cache, see if it's real, and try to add it
582 clazz = context.getClassLoader().loadClass(fname);
583 sClassMap.put(fname, clazz);
584 }
585 Fragment f = (Fragment)clazz.newInstance();
586 if (args != null) {
587 args.setClassLoader(f.getClass().getClassLoader());
588 f.mArguments = args;
589 }
590 return f;
591 } catch (ClassNotFoundException e) {
592 throw new InstantiationException("Unable to instantiate fragment " + fname
593 + ": make sure class name exists, is public, and has an"
594 + " empty constructor that is public", e);
595 } catch (java.lang.InstantiationException e) {
596 throw new InstantiationException("Unable to instantiate fragment " + fname
597 + ": make sure class name exists, is public, and has an"
598 + " empty constructor that is public", e);
599 } catch (IllegalAccessException e) {
600 throw new InstantiationException("Unable to instantiate fragment " + fname
601 + ": make sure class name exists, is public, and has an"
602 + " empty constructor that is public", e);
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700603 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700604 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700605
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700606 final void restoreViewState(Bundle savedInstanceState) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700607 if (mSavedViewState != null) {
608 mView.restoreHierarchyState(mSavedViewState);
609 mSavedViewState = null;
610 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700611 mCalled = false;
612 onViewStateRestored(savedInstanceState);
613 if (!mCalled) {
614 throw new SuperNotCalledException("Fragment " + this
615 + " did not call through to super.onViewStateRestored()");
616 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700617 }
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -0700618
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700619 final void setIndex(int index, Fragment parent) {
Dianne Hackborn6e8304e2010-05-14 00:42:53 -0700620 mIndex = index;
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700621 if (parent != null) {
622 mWho = parent.mWho + ":" + mIndex;
623 } else {
624 mWho = "android:fragment:" + mIndex;
625 }
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -0700626 }
627
Dianne Hackborn16f6e892011-04-15 19:00:20 -0700628 final boolean isInBackStack() {
629 return mBackStackNesting > 0;
630 }
631
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700632 /**
633 * Subclasses can not override equals().
634 */
635 @Override final public boolean equals(Object o) {
636 return super.equals(o);
637 }
638
639 /**
640 * Subclasses can not override hashCode().
641 */
642 @Override final public int hashCode() {
643 return super.hashCode();
644 }
645
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700646 @Override
647 public String toString() {
648 StringBuilder sb = new StringBuilder(128);
Dianne Hackborna2ea7472010-12-20 12:10:01 -0800649 DebugUtils.buildShortClassTag(this, sb);
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700650 if (mIndex >= 0) {
651 sb.append(" #");
652 sb.append(mIndex);
653 }
654 if (mFragmentId != 0) {
655 sb.append(" id=0x");
656 sb.append(Integer.toHexString(mFragmentId));
657 }
658 if (mTag != null) {
659 sb.append(" ");
660 sb.append(mTag);
661 }
662 sb.append('}');
663 return sb.toString();
664 }
665
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700666 /**
667 * Return the identifier this fragment is known by. This is either
668 * the android:id value supplied in a layout or the container view ID
669 * supplied when adding the fragment.
670 */
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700671 final public int getId() {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700672 return mFragmentId;
673 }
674
675 /**
676 * Get the tag name of the fragment, if specified.
677 */
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700678 final public String getTag() {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700679 return mTag;
680 }
681
682 /**
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700683 * Supply the construction arguments for this fragment. This can only
684 * be called before the fragment has been attached to its activity; that
685 * is, you should call it immediately after constructing the fragment. The
686 * arguments supplied here will be retained across fragment destroy and
687 * creation.
688 */
Dianne Hackborndef15372010-08-15 12:43:52 -0700689 public void setArguments(Bundle args) {
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700690 if (mIndex >= 0) {
691 throw new IllegalStateException("Fragment already active");
692 }
693 mArguments = args;
694 }
695
696 /**
697 * Return the arguments supplied when the fragment was instantiated,
698 * if any.
699 */
700 final public Bundle getArguments() {
701 return mArguments;
702 }
703
704 /**
Dianne Hackbornb46ed762011-06-02 18:33:15 -0700705 * Set the initial saved state that this Fragment should restore itself
706 * from when first being constructed, as returned by
707 * {@link FragmentManager#saveFragmentInstanceState(Fragment)
708 * FragmentManager.saveFragmentInstanceState}.
709 *
710 * @param state The state the fragment should be restored from.
711 */
712 public void setInitialSavedState(SavedState state) {
713 if (mIndex >= 0) {
714 throw new IllegalStateException("Fragment already active");
715 }
716 mSavedFragmentState = state != null && state.mState != null
717 ? state.mState : null;
718 }
719
720 /**
Dianne Hackborndef15372010-08-15 12:43:52 -0700721 * Optional target for this fragment. This may be used, for example,
722 * if this fragment is being started by another, and when done wants to
723 * give a result back to the first. The target set here is retained
724 * across instances via {@link FragmentManager#putFragment
725 * FragmentManager.putFragment()}.
726 *
727 * @param fragment The fragment that is the target of this one.
728 * @param requestCode Optional request code, for convenience if you
729 * are going to call back with {@link #onActivityResult(int, int, Intent)}.
730 */
731 public void setTargetFragment(Fragment fragment, int requestCode) {
732 mTarget = fragment;
733 mTargetRequestCode = requestCode;
734 }
735
736 /**
Dianne Hackborn3f00be52010-08-15 18:03:27 -0700737 * Return the target fragment set by {@link #setTargetFragment}.
Dianne Hackborndef15372010-08-15 12:43:52 -0700738 */
739 final public Fragment getTargetFragment() {
740 return mTarget;
741 }
742
743 /**
Dianne Hackborn3f00be52010-08-15 18:03:27 -0700744 * Return the target request code set by {@link #setTargetFragment}.
Dianne Hackborndef15372010-08-15 12:43:52 -0700745 */
746 final public int getTargetRequestCode() {
747 return mTargetRequestCode;
748 }
749
750 /**
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700751 * Return the Activity this fragment is currently associated with.
752 */
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700753 final public Activity getActivity() {
Dianne Hackborn2dedce62010-04-15 14:45:25 -0700754 return mActivity;
755 }
756
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700757 /**
Dianne Hackbornbdd19bc2010-11-10 23:27:54 -0800758 * Return <code>getActivity().getResources()</code>.
759 */
760 final public Resources getResources() {
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -0800761 if (mActivity == null) {
762 throw new IllegalStateException("Fragment " + this + " not attached to Activity");
763 }
Dianne Hackbornbdd19bc2010-11-10 23:27:54 -0800764 return mActivity.getResources();
765 }
766
767 /**
768 * Return a localized, styled CharSequence from the application's package's
769 * default string table.
770 *
771 * @param resId Resource id for the CharSequence text
772 */
773 public final CharSequence getText(int resId) {
774 return getResources().getText(resId);
775 }
776
777 /**
778 * Return a localized string from the application's package's
779 * default string table.
780 *
781 * @param resId Resource id for the string
782 */
783 public final String getString(int resId) {
784 return getResources().getString(resId);
785 }
786
787 /**
788 * Return a localized formatted string from the application's package's
789 * default string table, substituting the format arguments as defined in
790 * {@link java.util.Formatter} and {@link java.lang.String#format}.
791 *
792 * @param resId Resource id for the format string
793 * @param formatArgs The format arguments that will be used for substitution.
794 */
795
796 public final String getString(int resId, Object... formatArgs) {
797 return getResources().getString(resId, formatArgs);
798 }
799
800 /**
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700801 * Return the FragmentManager for interacting with fragments associated
Dianne Hackborn3e449ce2010-09-11 20:52:31 -0700802 * with this fragment's activity. Note that this will be non-null slightly
Dianne Hackborn625ac272010-09-17 18:29:22 -0700803 * before {@link #getActivity()}, during the time from when the fragment is
Dianne Hackborn3e449ce2010-09-11 20:52:31 -0700804 * placed in a {@link FragmentTransaction} until it is committed and
805 * attached to its activity.
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700806 *
807 * <p>If this Fragment is a child of another Fragment, the FragmentManager
808 * returned here will be the parent's {@link #getChildFragmentManager()}.
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700809 */
810 final public FragmentManager getFragmentManager() {
Dianne Hackborn3e449ce2010-09-11 20:52:31 -0700811 return mFragmentManager;
Dianne Hackbornb7a2e472010-08-12 16:20:42 -0700812 }
813
814 /**
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700815 * Return a private FragmentManager for placing and managing Fragments
816 * inside of this Fragment.
817 */
818 final public FragmentManager getChildFragmentManager() {
819 if (mChildFragmentManager == null) {
820 instantiateChildFragmentManager();
821 if (mState >= RESUMED) {
822 mChildFragmentManager.dispatchResume();
823 } else if (mState >= STARTED) {
824 mChildFragmentManager.dispatchStart();
825 } else if (mState >= ACTIVITY_CREATED) {
826 mChildFragmentManager.dispatchActivityCreated();
827 } else if (mState >= CREATED) {
828 mChildFragmentManager.dispatchCreate();
829 }
830 }
831 return mChildFragmentManager;
832 }
833
834 /**
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -0700835 * Returns the parent Fragment containing this Fragment. If this Fragment
836 * is attached directly to an Activity, returns null.
837 */
838 final public Fragment getParentFragment() {
839 return mParentFragment;
840 }
841
842 /**
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700843 * Return true if the fragment is currently added to its activity.
844 */
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700845 final public boolean isAdded() {
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -0800846 return mActivity != null && mAdded;
847 }
848
849 /**
Dianne Hackbornafc4b282011-06-10 17:03:42 -0700850 * Return true if the fragment has been explicitly detached from the UI.
851 * That is, {@link FragmentTransaction#detach(Fragment)
852 * FragmentTransaction.detach(Fragment)} has been used on it.
853 */
854 final public boolean isDetached() {
855 return mDetached;
856 }
857
858 /**
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -0800859 * Return true if this fragment is currently being removed from its
860 * activity. This is <em>not</em> whether its activity is finishing, but
861 * rather whether it is in the process of being removed from its activity.
862 */
863 final public boolean isRemoving() {
864 return mRemoving;
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700865 }
866
867 /**
Dianne Hackborn625ac272010-09-17 18:29:22 -0700868 * Return true if the layout is included as part of an activity view
869 * hierarchy via the &lt;fragment&gt; tag. This will always be true when
870 * fragments are created through the &lt;fragment&gt; tag, <em>except</em>
871 * in the case where an old fragment is restored from a previous state and
872 * it does not appear in the layout of the current state.
873 */
874 final public boolean isInLayout() {
875 return mInLayout;
876 }
877
878 /**
Dianne Hackborn2707d602010-07-09 18:01:20 -0700879 * Return true if the fragment is in the resumed state. This is true
880 * for the duration of {@link #onResume()} and {@link #onPause()} as well.
881 */
882 final public boolean isResumed() {
883 return mResumed;
884 }
885
886 /**
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700887 * Return true if the fragment is currently visible to the user. This means
888 * it: (1) has been added, (2) has its view attached to the window, and
889 * (3) is not hidden.
890 */
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700891 final public boolean isVisible() {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700892 return isAdded() && !isHidden() && mView != null
893 && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
894 }
895
896 /**
897 * Return true if the fragment has been hidden. By default fragments
898 * are shown. You can find out about changes to this state with
Dianne Hackborncddfa6d2010-05-19 22:56:37 -0700899 * {@link #onHiddenChanged}. Note that the hidden state is orthogonal
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700900 * to other states -- that is, to be visible to the user, a fragment
901 * must be both started and not hidden.
902 */
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700903 final public boolean isHidden() {
Dianne Hackborn5ae74d62010-05-19 19:14:57 -0700904 return mHidden;
905 }
906
907 /**
908 * Called when the hidden state (as returned by {@link #isHidden()} of
909 * the fragment has changed. Fragments start out not hidden; this will
910 * be called whenever the fragment changes state from that.
911 * @param hidden True if the fragment is now hidden, false if it is not
912 * visible.
913 */
914 public void onHiddenChanged(boolean hidden) {
915 }
916
917 /**
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700918 * Control whether a fragment instance is retained across Activity
919 * re-creation (such as from a configuration change). This can only
920 * be used with fragments not in the back stack. If set, the fragment
921 * lifecycle will be slightly different when an activity is recreated:
922 * <ul>
923 * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
924 * will be, because the fragment is being detached from its current activity).
925 * <li> {@link #onCreate(Bundle)} will not be called since the fragment
926 * is not being re-created.
Dianne Hackbornc8017682010-07-06 13:34:38 -0700927 * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700928 * still be called.
929 * </ul>
930 */
931 public void setRetainInstance(boolean retain) {
Dianne Hackborn62bea2f2012-09-04 18:48:15 -0700932 if (retain && mParentFragment != null) {
933 throw new IllegalStateException(
934 "Can't retain fragements that are nested in other fragments");
935 }
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700936 mRetainInstance = retain;
937 }
938
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700939 final public boolean getRetainInstance() {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -0700940 return mRetainInstance;
941 }
942
943 /**
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700944 * Report that this fragment would like to participate in populating
Wink Saville4dc643e2010-06-12 22:16:41 -0700945 * the options menu by receiving a call to {@link #onCreateOptionsMenu}
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700946 * and related methods.
947 *
948 * @param hasMenu If true, the fragment has menu items to contribute.
949 */
950 public void setHasOptionsMenu(boolean hasMenu) {
951 if (mHasMenu != hasMenu) {
952 mHasMenu = hasMenu;
Adam Powellf0f5fff2011-08-01 13:42:50 -0700953 if (isAdded() && !isHidden()) {
954 mFragmentManager.invalidateOptionsMenu();
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700955 }
956 }
957 }
Dianne Hackborn6c285972011-08-29 16:53:49 -0700958
959 /**
960 * Set a hint for whether this fragment's menu should be visible. This
961 * is useful if you know that a fragment has been placed in your view
962 * hierarchy so that the user can not currently seen it, so any menu items
963 * it has should also not be shown.
964 *
965 * @param menuVisible The default is true, meaning the fragment's menu will
966 * be shown as usual. If false, the user will not see the menu.
967 */
968 public void setMenuVisibility(boolean menuVisible) {
969 if (mMenuVisible != menuVisible) {
970 mMenuVisible = menuVisible;
971 if (mHasMenu && isAdded() && !isHidden()) {
972 mFragmentManager.invalidateOptionsMenu();
973 }
974 }
975 }
976
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -0700977 /**
Adam Powell78fed9b2011-11-07 10:45:34 -0800978 * Set a hint to the system about whether this fragment's UI is currently visible
979 * to the user. This hint defaults to true and is persistent across fragment instance
980 * state save and restore.
Adam Powell635c60a2011-10-26 10:22:16 -0700981 *
Adam Powell78fed9b2011-11-07 10:45:34 -0800982 * <p>An app may set this to false to indicate that the fragment's UI is
983 * scrolled out of visibility or is otherwise not directly visible to the user.
984 * This may be used by the system to prioritize operations such as fragment lifecycle updates
985 * or loader ordering behavior.</p>
Adam Powell635c60a2011-10-26 10:22:16 -0700986 *
Adam Powell78fed9b2011-11-07 10:45:34 -0800987 * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default),
988 * false if it is not.
Adam Powell635c60a2011-10-26 10:22:16 -0700989 */
Adam Powell78fed9b2011-11-07 10:45:34 -0800990 public void setUserVisibleHint(boolean isVisibleToUser) {
991 if (!mUserVisibleHint && isVisibleToUser && mState < STARTED) {
Adam Powell635c60a2011-10-26 10:22:16 -0700992 mFragmentManager.performPendingDeferredStart(this);
993 }
Adam Powell78fed9b2011-11-07 10:45:34 -0800994 mUserVisibleHint = isVisibleToUser;
995 mDeferStart = !isVisibleToUser;
Adam Powell635c60a2011-10-26 10:22:16 -0700996 }
997
998 /**
Adam Powell78fed9b2011-11-07 10:45:34 -0800999 * @return The current value of the user-visible hint on this fragment.
1000 * @see #setUserVisibleHint(boolean)
Adam Powell635c60a2011-10-26 10:22:16 -07001001 */
Adam Powell78fed9b2011-11-07 10:45:34 -08001002 public boolean getUserVisibleHint() {
1003 return mUserVisibleHint;
Adam Powell635c60a2011-10-26 10:22:16 -07001004 }
1005
1006 /**
Dianne Hackbornc8017682010-07-06 13:34:38 -07001007 * Return the LoaderManager for this fragment, creating it if needed.
1008 */
1009 public LoaderManager getLoaderManager() {
1010 if (mLoaderManager != null) {
1011 return mLoaderManager;
1012 }
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08001013 if (mActivity == null) {
1014 throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1015 }
Dianne Hackborn5e0d5952010-08-05 13:45:35 -07001016 mCheckedForLoaderManager = true;
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001017 mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, true);
Dianne Hackbornc8017682010-07-06 13:34:38 -07001018 return mLoaderManager;
1019 }
Dianne Hackborna4972e92012-03-14 10:38:05 -07001020
Dianne Hackbornc8017682010-07-06 13:34:38 -07001021 /**
Scott Main87bff972013-02-27 15:46:34 -08001022 * Call {@link Activity#startActivity(Intent)} from the fragment's
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001023 * containing Activity.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001024 *
1025 * @param intent The intent to start.
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001026 */
1027 public void startActivity(Intent intent) {
Dianne Hackborna4972e92012-03-14 10:38:05 -07001028 startActivity(intent, null);
1029 }
1030
1031 /**
Scott Main87bff972013-02-27 15:46:34 -08001032 * Call {@link Activity#startActivity(Intent, Bundle)} from the fragment's
Dianne Hackborna4972e92012-03-14 10:38:05 -07001033 * containing Activity.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001034 *
1035 * @param intent The intent to start.
1036 * @param options Additional options for how the Activity should be started.
1037 * See {@link android.content.Context#startActivity(Intent, Bundle)
1038 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001039 */
1040 public void startActivity(Intent intent, Bundle options) {
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08001041 if (mActivity == null) {
1042 throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1043 }
Dianne Hackborna4972e92012-03-14 10:38:05 -07001044 if (options != null) {
1045 mActivity.startActivityFromFragment(this, intent, -1, options);
1046 } else {
1047 // Note we want to go through this call for compatibility with
1048 // applications that may have overridden the method.
1049 mActivity.startActivityFromFragment(this, intent, -1);
1050 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001051 }
Dianne Hackborna4972e92012-03-14 10:38:05 -07001052
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001053 /**
Scott Main87bff972013-02-27 15:46:34 -08001054 * Call {@link Activity#startActivityForResult(Intent, int)} from the fragment's
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001055 * containing Activity.
1056 */
1057 public void startActivityForResult(Intent intent, int requestCode) {
Dianne Hackborna4972e92012-03-14 10:38:05 -07001058 startActivityForResult(intent, requestCode, null);
1059 }
1060
1061 /**
Scott Main87bff972013-02-27 15:46:34 -08001062 * Call {@link Activity#startActivityForResult(Intent, int, Bundle)} from the fragment's
Dianne Hackborna4972e92012-03-14 10:38:05 -07001063 * containing Activity.
1064 */
1065 public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08001066 if (mActivity == null) {
1067 throw new IllegalStateException("Fragment " + this + " not attached to Activity");
1068 }
Dianne Hackborna4972e92012-03-14 10:38:05 -07001069 if (options != null) {
1070 mActivity.startActivityFromFragment(this, intent, requestCode, options);
1071 } else {
1072 // Note we want to go through this call for compatibility with
1073 // applications that may have overridden the method.
1074 mActivity.startActivityFromFragment(this, intent, requestCode, options);
1075 }
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001076 }
1077
1078 /**
1079 * Receive the result from a previous call to
1080 * {@link #startActivityForResult(Intent, int)}. This follows the
1081 * related Activity API as described there in
1082 * {@link Activity#onActivityResult(int, int, Intent)}.
1083 *
1084 * @param requestCode The integer request code originally supplied to
1085 * startActivityForResult(), allowing you to identify who this
1086 * result came from.
1087 * @param resultCode The integer result code returned by the child activity
1088 * through its setResult().
1089 * @param data An Intent, which can return result data to the caller
1090 * (various data can be attached to Intent "extras").
1091 */
1092 public void onActivityResult(int requestCode, int resultCode, Intent data) {
1093 }
1094
1095 /**
Dianne Hackborn7187ccb2011-01-24 23:58:13 -08001096 * @hide Hack so that DialogFragment can make its Dialog before creating
1097 * its views, and the view construction can use the dialog's context for
1098 * inflation. Maybe this should become a public API. Note sure.
1099 */
1100 public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
1101 return mActivity.getLayoutInflater();
1102 }
1103
1104 /**
Dianne Hackborne3a7f622011-03-03 21:48:24 -08001105 * @deprecated Use {@link #onInflate(Activity, AttributeSet, Bundle)} instead.
1106 */
1107 @Deprecated
1108 public void onInflate(AttributeSet attrs, Bundle savedInstanceState) {
1109 mCalled = true;
1110 }
1111
1112 /**
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001113 * Called when a fragment is being created as part of a view layout
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001114 * inflation, typically from setting the content view of an activity. This
Dianne Hackborne3a7f622011-03-03 21:48:24 -08001115 * may be called immediately after the fragment is created from a <fragment>
Dianne Hackborndef15372010-08-15 12:43:52 -07001116 * tag in a layout file. Note this is <em>before</em> the fragment's
1117 * {@link #onAttach(Activity)} has been called; all you should do here is
Dianne Hackborne3a7f622011-03-03 21:48:24 -08001118 * parse the attributes and save them away.
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001119 *
Dianne Hackborndef15372010-08-15 12:43:52 -07001120 * <p>This is called every time the fragment is inflated, even if it is
Dianne Hackborne3a7f622011-03-03 21:48:24 -08001121 * being inflated into a new instance with saved state. It typically makes
1122 * sense to re-parse the parameters each time, to allow them to change with
1123 * different configurations.</p>
1124 *
1125 * <p>Here is a typical implementation of a fragment that can take parameters
1126 * both through attributes supplied here as well from {@link #getArguments()}:</p>
1127 *
1128 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
1129 * fragment}
1130 *
1131 * <p>Note that parsing the XML attributes uses a "styleable" resource. The
1132 * declaration for the styleable used here is:</p>
1133 *
1134 * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001135 *
Dianne Hackborne3a7f622011-03-03 21:48:24 -08001136 * <p>The fragment can then be declared within its activity's content layout
1137 * through a tag like this:</p>
1138 *
1139 * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
1140 *
1141 * <p>This fragment can also be created dynamically from arguments given
1142 * at runtime in the arguments Bundle; here is an example of doing so at
1143 * creation of the containing activity:</p>
1144 *
1145 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
1146 * create}
1147 *
1148 * @param activity The Activity that is inflating this fragment.
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001149 * @param attrs The attributes at the tag where the fragment is
1150 * being created.
Dianne Hackborn6e8304e2010-05-14 00:42:53 -07001151 * @param savedInstanceState If the fragment is being re-created from
1152 * a previous saved state, this is the state.
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001153 */
Dianne Hackborne3a7f622011-03-03 21:48:24 -08001154 public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
1155 onInflate(attrs, savedInstanceState);
Dianne Hackbornba51c3d2010-05-05 18:49:48 -07001156 mCalled = true;
1157 }
1158
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001159 /**
1160 * Called when a fragment is first attached to its activity.
1161 * {@link #onCreate(Bundle)} will be called after this.
1162 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001163 public void onAttach(Activity activity) {
1164 mCalled = true;
1165 }
1166
Chet Haase811ed1062010-08-06 10:38:15 -07001167 /**
1168 * Called when a fragment loads an animation.
1169 */
Chet Haasea18a86b2010-09-07 13:20:00 -07001170 public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
Dianne Hackbornf121be72010-05-06 14:10:32 -07001171 return null;
1172 }
1173
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001174 /**
1175 * Called to do initial creation of a fragment. This is called after
Dianne Hackbornc8017682010-07-06 13:34:38 -07001176 * {@link #onAttach(Activity)} and before
1177 * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1178 *
1179 * <p>Note that this can be called while the fragment's activity is
1180 * still in the process of being created. As such, you can not rely
1181 * on things like the activity's content view hierarchy being initialized
1182 * at this point. If you want to do work once the activity itself is
1183 * created, see {@link #onActivityCreated(Bundle)}.
1184 *
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001185 * @param savedInstanceState If the fragment is being re-created from
1186 * a previous saved state, this is the state.
1187 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001188 public void onCreate(Bundle savedInstanceState) {
1189 mCalled = true;
1190 }
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001191
Dianne Hackborn16f6e892011-04-15 19:00:20 -07001192 /**
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001193 * Called to have the fragment instantiate its user interface view.
1194 * This is optional, and non-graphical fragments can return null (which
1195 * is the default implementation). This will be called between
Dianne Hackbornc8017682010-07-06 13:34:38 -07001196 * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001197 *
Dianne Hackborn5ddd1272010-06-12 10:15:28 -07001198 * <p>If you return a View from here, you will later be called in
1199 * {@link #onDestroyView} when the view is being released.
1200 *
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001201 * @param inflater The LayoutInflater object that can be used to inflate
1202 * any views in the fragment,
1203 * @param container If non-null, this is the parent view that the fragment's
1204 * UI should be attached to. The fragment should not add the view itself,
1205 * but this can be used to generate the LayoutParams of the view.
1206 * @param savedInstanceState If non-null, this fragment is being re-constructed
1207 * from a previous saved state as given here.
1208 *
1209 * @return Return the View for the fragment's UI, or null.
1210 */
1211 public View onCreateView(LayoutInflater inflater, ViewGroup container,
1212 Bundle savedInstanceState) {
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001213 return null;
1214 }
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001215
1216 /**
1217 * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
1218 * has returned, but before any saved state has been restored in to the view.
1219 * This gives subclasses a chance to initialize themselves once
1220 * they know their view hierarchy has been completely created. The fragment's
1221 * view hierarchy is not however attached to its parent at this point.
1222 * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
1223 * @param savedInstanceState If non-null, this fragment is being re-constructed
1224 * from a previous saved state as given here.
1225 */
1226 public void onViewCreated(View view, Bundle savedInstanceState) {
1227 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001228
Scott Main662cc7a42011-01-17 15:02:07 -08001229 /**
1230 * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
1231 * if provided.
1232 *
1233 * @return The fragment's root view, or null if it has no layout.
1234 */
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001235 public View getView() {
1236 return mView;
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001237 }
1238
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001239 /**
Dianne Hackbornc8017682010-07-06 13:34:38 -07001240 * Called when the fragment's activity has been created and this
1241 * fragment's view hierarchy instantiated. It can be used to do final
1242 * initialization once these pieces are in place, such as retrieving
1243 * views or restoring state. It is also useful for fragments that use
1244 * {@link #setRetainInstance(boolean)} to retain their instance,
1245 * as this callback tells the fragment when it is fully associated with
Dianne Hackborn5ddd1272010-06-12 10:15:28 -07001246 * the new activity instance. This is called after {@link #onCreateView}
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001247 * and before {@link #onViewStateRestored(Bundle)}.
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001248 *
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001249 * @param savedInstanceState If the fragment is being re-created from
1250 * a previous saved state, this is the state.
1251 */
Dianne Hackbornc8017682010-07-06 13:34:38 -07001252 public void onActivityCreated(Bundle savedInstanceState) {
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001253 mCalled = true;
1254 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001255
1256 /**
1257 * Called when all saved state has been restored into the view hierarchy
1258 * of the fragment. This can be used to do initialization based on saved
1259 * state that you are letting the view hierarchy track itself, such as
1260 * whether check box widgets are currently checked. This is called
1261 * after {@link #onActivityCreated(Bundle)} and before
1262 * {@link #onStart()}.
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001263 *
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001264 * @param savedInstanceState If the fragment is being re-created from
1265 * a previous saved state, this is the state.
1266 */
1267 public void onViewStateRestored(Bundle savedInstanceState) {
1268 mCalled = true;
1269 }
1270
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001271 /**
1272 * Called when the Fragment is visible to the user. This is generally
1273 * tied to {@link Activity#onStart() Activity.onStart} of the containing
1274 * Activity's lifecycle.
1275 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001276 public void onStart() {
1277 mCalled = true;
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07001278
1279 if (!mLoadersStarted) {
1280 mLoadersStarted = true;
1281 if (!mCheckedForLoaderManager) {
1282 mCheckedForLoaderManager = true;
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001283 mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false);
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07001284 }
1285 if (mLoaderManager != null) {
1286 mLoaderManager.doStart();
1287 }
Dianne Hackbornc8017682010-07-06 13:34:38 -07001288 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001289 }
1290
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001291 /**
1292 * Called when the fragment is visible to the user and actively running.
1293 * This is generally
1294 * tied to {@link Activity#onResume() Activity.onResume} of the containing
1295 * Activity's lifecycle.
1296 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001297 public void onResume() {
1298 mCalled = true;
1299 }
1300
Dianne Hackborn72778202010-08-20 18:26:01 -07001301 /**
1302 * Called to ask the fragment to save its current dynamic state, so it
1303 * can later be reconstructed in a new instance of its process is
1304 * restarted. If a new instance of the fragment later needs to be
1305 * created, the data you place in the Bundle here will be available
1306 * in the Bundle given to {@link #onCreate(Bundle)},
1307 * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and
1308 * {@link #onActivityCreated(Bundle)}.
1309 *
1310 * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle)
Daisuke Miyakawa2f761762010-09-12 16:53:17 -07001311 * Activity.onSaveInstanceState(Bundle)} and most of the discussion there
Dianne Hackborn72778202010-08-20 18:26:01 -07001312 * applies here as well. Note however: <em>this method may be called
1313 * at any time before {@link #onDestroy()}</em>. There are many situations
1314 * where a fragment may be mostly torn down (such as when placed on the
1315 * back stack with no UI showing), but its state will not be saved until
1316 * its owning activity actually needs to save its state.
1317 *
1318 * @param outState Bundle in which to place your saved state.
1319 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001320 public void onSaveInstanceState(Bundle outState) {
1321 }
1322
1323 public void onConfigurationChanged(Configuration newConfig) {
1324 mCalled = true;
1325 }
1326
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001327 /**
1328 * Called when the Fragment is no longer resumed. This is generally
1329 * tied to {@link Activity#onPause() Activity.onPause} of the containing
1330 * Activity's lifecycle.
1331 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001332 public void onPause() {
1333 mCalled = true;
1334 }
1335
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001336 /**
1337 * Called when the Fragment is no longer started. This is generally
1338 * tied to {@link Activity#onStop() Activity.onStop} of the containing
1339 * Activity's lifecycle.
1340 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001341 public void onStop() {
1342 mCalled = true;
1343 }
1344
1345 public void onLowMemory() {
1346 mCalled = true;
1347 }
1348
Dianne Hackbornc68c9132011-07-29 01:25:18 -07001349 public void onTrimMemory(int level) {
1350 mCalled = true;
1351 }
1352
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001353 /**
Dianne Hackborn5ddd1272010-06-12 10:15:28 -07001354 * Called when the view previously created by {@link #onCreateView} has
1355 * been detached from the fragment. The next time the fragment needs
1356 * to be displayed, a new view will be created. This is called
Dianne Hackborndef15372010-08-15 12:43:52 -07001357 * after {@link #onStop()} and before {@link #onDestroy()}. It is called
1358 * <em>regardless</em> of whether {@link #onCreateView} returned a
1359 * non-null view. Internally it is called after the view's state has
1360 * been saved but before it has been removed from its parent.
Dianne Hackborn5ddd1272010-06-12 10:15:28 -07001361 */
1362 public void onDestroyView() {
1363 mCalled = true;
1364 }
1365
1366 /**
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001367 * Called when the fragment is no longer in use. This is called
1368 * after {@link #onStop()} and before {@link #onDetach()}.
1369 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001370 public void onDestroy() {
1371 mCalled = true;
Dianne Hackborn5e0d5952010-08-05 13:45:35 -07001372 //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager
1373 // + " mLoaderManager=" + mLoaderManager);
1374 if (!mCheckedForLoaderManager) {
1375 mCheckedForLoaderManager = true;
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001376 mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false);
Dianne Hackborn5e0d5952010-08-05 13:45:35 -07001377 }
Dianne Hackbornc8017682010-07-06 13:34:38 -07001378 if (mLoaderManager != null) {
1379 mLoaderManager.doDestroy();
1380 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001381 }
Dianne Hackborn5ae74d62010-05-19 19:14:57 -07001382
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001383 /**
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001384 * Called by the fragment manager once this fragment has been removed,
1385 * so that we don't have any left-over state if the application decides
1386 * to re-use the instance. This only clears state that the framework
1387 * internally manages, not things the application sets.
1388 */
1389 void initState() {
1390 mIndex = -1;
1391 mWho = null;
1392 mAdded = false;
1393 mRemoving = false;
1394 mResumed = false;
1395 mFromLayout = false;
1396 mInLayout = false;
1397 mRestored = false;
1398 mBackStackNesting = 0;
1399 mFragmentManager = null;
Dianne Hackborn6c285972011-08-29 16:53:49 -07001400 mActivity = null;
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001401 mFragmentId = 0;
1402 mContainerId = 0;
1403 mTag = null;
1404 mHidden = false;
1405 mDetached = false;
1406 mRetaining = false;
1407 mLoaderManager = null;
1408 mLoadersStarted = false;
1409 mCheckedForLoaderManager = false;
1410 }
1411
1412 /**
Dianne Hackbornb4bc78b2010-05-12 18:59:50 -07001413 * Called when the fragment is no longer attached to its activity. This
1414 * is called after {@link #onDestroy()}.
1415 */
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001416 public void onDetach() {
1417 mCalled = true;
1418 }
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -07001419
1420 /**
1421 * Initialize the contents of the Activity's standard options menu. You
1422 * should place your menu items in to <var>menu</var>. For this method
Dianne Hackborn5ddd1272010-06-12 10:15:28 -07001423 * to be called, you must have first called {@link #setHasOptionsMenu}. See
1424 * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
1425 * for more information.
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -07001426 *
1427 * @param menu The options menu in which you place your items.
1428 *
Wink Saville4dc643e2010-06-12 22:16:41 -07001429 * @see #setHasOptionsMenu
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -07001430 * @see #onPrepareOptionsMenu
1431 * @see #onOptionsItemSelected
1432 */
1433 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1434 }
1435
1436 /**
1437 * Prepare the Screen's standard options menu to be displayed. This is
1438 * called right before the menu is shown, every time it is shown. You can
1439 * use this method to efficiently enable/disable items or otherwise
1440 * dynamically modify the contents. See
1441 * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
1442 * for more information.
1443 *
1444 * @param menu The options menu as last shown or first initialized by
1445 * onCreateOptionsMenu().
1446 *
Wink Saville4dc643e2010-06-12 22:16:41 -07001447 * @see #setHasOptionsMenu
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -07001448 * @see #onCreateOptionsMenu
1449 */
1450 public void onPrepareOptionsMenu(Menu menu) {
1451 }
1452
1453 /**
Dianne Hackborn8eb2e242010-11-01 12:31:24 -07001454 * Called when this fragment's option menu items are no longer being
1455 * included in the overall options menu. Receiving this call means that
1456 * the menu needed to be rebuilt, but this fragment's items were not
1457 * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)}
1458 * was not called).
1459 */
1460 public void onDestroyOptionsMenu() {
1461 }
1462
1463 /**
Dianne Hackbornb31e84bc2010-06-08 18:04:35 -07001464 * This hook is called whenever an item in your options menu is selected.
1465 * The default implementation simply returns false to have the normal
1466 * processing happen (calling the item's Runnable or sending a message to
1467 * its Handler as appropriate). You can use this method for any items
1468 * for which you would like to do processing without those other
1469 * facilities.
1470 *
1471 * <p>Derived classes should call through to the base class for it to
1472 * perform the default menu handling.
1473 *
1474 * @param item The menu item that was selected.
1475 *
1476 * @return boolean Return false to allow normal menu processing to
1477 * proceed, true to consume it here.
1478 *
1479 * @see #onCreateOptionsMenu
1480 */
1481 public boolean onOptionsItemSelected(MenuItem item) {
1482 return false;
1483 }
1484
1485 /**
1486 * This hook is called whenever the options menu is being closed (either by the user canceling
1487 * the menu with the back/menu button, or when an item is selected).
1488 *
1489 * @param menu The options menu as last shown or first initialized by
1490 * onCreateOptionsMenu().
1491 */
1492 public void onOptionsMenuClosed(Menu menu) {
1493 }
Dianne Hackborn5ddd1272010-06-12 10:15:28 -07001494
1495 /**
1496 * Called when a context menu for the {@code view} is about to be shown.
1497 * Unlike {@link #onCreateOptionsMenu}, this will be called every
1498 * time the context menu is about to be shown and should be populated for
1499 * the view (or item inside the view for {@link AdapterView} subclasses,
1500 * this can be found in the {@code menuInfo})).
1501 * <p>
1502 * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
1503 * item has been selected.
1504 * <p>
1505 * The default implementation calls up to
1506 * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
1507 * you can not call this implementation if you don't want that behavior.
1508 * <p>
1509 * It is not safe to hold onto the context menu after this method returns.
1510 * {@inheritDoc}
1511 */
1512 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
1513 getActivity().onCreateContextMenu(menu, v, menuInfo);
1514 }
1515
1516 /**
1517 * Registers a context menu to be shown for the given view (multiple views
1518 * can show the context menu). This method will set the
1519 * {@link OnCreateContextMenuListener} on the view to this fragment, so
1520 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
1521 * called when it is time to show the context menu.
1522 *
1523 * @see #unregisterForContextMenu(View)
1524 * @param view The view that should show a context menu.
1525 */
1526 public void registerForContextMenu(View view) {
1527 view.setOnCreateContextMenuListener(this);
1528 }
1529
1530 /**
1531 * Prevents a context menu to be shown for the given view. This method will
1532 * remove the {@link OnCreateContextMenuListener} on the view.
1533 *
1534 * @see #registerForContextMenu(View)
1535 * @param view The view that should stop showing a context menu.
1536 */
1537 public void unregisterForContextMenu(View view) {
1538 view.setOnCreateContextMenuListener(null);
1539 }
1540
1541 /**
1542 * This hook is called whenever an item in a context menu is selected. The
1543 * default implementation simply returns false to have the normal processing
1544 * happen (calling the item's Runnable or sending a message to its Handler
1545 * as appropriate). You can use this method for any items for which you
1546 * would like to do processing without those other facilities.
1547 * <p>
1548 * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
1549 * View that added this menu item.
1550 * <p>
1551 * Derived classes should call through to the base class for it to perform
1552 * the default menu handling.
1553 *
1554 * @param item The context menu item that was selected.
1555 * @return boolean Return false to allow normal context menu processing to
1556 * proceed, true to consume it here.
1557 */
1558 public boolean onContextItemSelected(MenuItem item) {
1559 return false;
1560 }
Dianne Hackborn2707d602010-07-09 18:01:20 -07001561
Dianne Hackborn625ac272010-09-17 18:29:22 -07001562 /**
1563 * Print the Fragments's state into the given stream.
1564 *
1565 * @param prefix Text to print at the front of each line.
1566 * @param fd The raw file descriptor that the dump is being sent to.
1567 * @param writer The PrintWriter to which you should dump your state. This will be
1568 * closed for you after you return.
1569 * @param args additional arguments to the dump request.
1570 */
1571 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
Dianne Hackborn30d71892010-12-11 10:37:55 -08001572 writer.print(prefix); writer.print("mFragmentId=#");
1573 writer.print(Integer.toHexString(mFragmentId));
Dianne Hackbornee76efb2012-06-05 10:27:40 -07001574 writer.print(" mContainerId=#");
Dianne Hackborn30d71892010-12-11 10:37:55 -08001575 writer.print(Integer.toHexString(mContainerId));
Dianne Hackborn625ac272010-09-17 18:29:22 -07001576 writer.print(" mTag="); writer.println(mTag);
1577 writer.print(prefix); writer.print("mState="); writer.print(mState);
1578 writer.print(" mIndex="); writer.print(mIndex);
1579 writer.print(" mWho="); writer.print(mWho);
1580 writer.print(" mBackStackNesting="); writer.println(mBackStackNesting);
1581 writer.print(prefix); writer.print("mAdded="); writer.print(mAdded);
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08001582 writer.print(" mRemoving="); writer.print(mRemoving);
Dianne Hackborn625ac272010-09-17 18:29:22 -07001583 writer.print(" mResumed="); writer.print(mResumed);
1584 writer.print(" mFromLayout="); writer.print(mFromLayout);
1585 writer.print(" mInLayout="); writer.println(mInLayout);
1586 writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
Dianne Hackborn16f6e892011-04-15 19:00:20 -07001587 writer.print(" mDetached="); writer.print(mDetached);
Dianne Hackborn6c285972011-08-29 16:53:49 -07001588 writer.print(" mMenuVisible="); writer.print(mMenuVisible);
Dianne Hackborn625ac272010-09-17 18:29:22 -07001589 writer.print(" mHasMenu="); writer.println(mHasMenu);
Dianne Hackborn6c285972011-08-29 16:53:49 -07001590 writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance);
Adam Powell78fed9b2011-11-07 10:45:34 -08001591 writer.print(" mRetaining="); writer.print(mRetaining);
1592 writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint);
Dianne Hackborn625ac272010-09-17 18:29:22 -07001593 if (mFragmentManager != null) {
1594 writer.print(prefix); writer.print("mFragmentManager=");
1595 writer.println(mFragmentManager);
1596 }
Dianne Hackborn625ac272010-09-17 18:29:22 -07001597 if (mActivity != null) {
1598 writer.print(prefix); writer.print("mActivity=");
1599 writer.println(mActivity);
1600 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001601 if (mParentFragment != null) {
1602 writer.print(prefix); writer.print("mParentFragment=");
1603 writer.println(mParentFragment);
1604 }
Dianne Hackborn625ac272010-09-17 18:29:22 -07001605 if (mArguments != null) {
1606 writer.print(prefix); writer.print("mArguments="); writer.println(mArguments);
1607 }
1608 if (mSavedFragmentState != null) {
1609 writer.print(prefix); writer.print("mSavedFragmentState=");
1610 writer.println(mSavedFragmentState);
1611 }
1612 if (mSavedViewState != null) {
1613 writer.print(prefix); writer.print("mSavedViewState=");
1614 writer.println(mSavedViewState);
1615 }
1616 if (mTarget != null) {
1617 writer.print(prefix); writer.print("mTarget="); writer.print(mTarget);
1618 writer.print(" mTargetRequestCode=");
1619 writer.println(mTargetRequestCode);
1620 }
1621 if (mNextAnim != 0) {
1622 writer.print(prefix); writer.print("mNextAnim="); writer.println(mNextAnim);
1623 }
1624 if (mContainer != null) {
1625 writer.print(prefix); writer.print("mContainer="); writer.println(mContainer);
1626 }
1627 if (mView != null) {
1628 writer.print(prefix); writer.print("mView="); writer.println(mView);
1629 }
Dianne Hackbornd173fa32010-12-23 13:58:22 -08001630 if (mAnimatingAway != null) {
1631 writer.print(prefix); writer.print("mAnimatingAway="); writer.println(mAnimatingAway);
1632 writer.print(prefix); writer.print("mStateAfterAnimating=");
1633 writer.println(mStateAfterAnimating);
1634 }
Dianne Hackborn625ac272010-09-17 18:29:22 -07001635 if (mLoaderManager != null) {
Dianne Hackborn30d71892010-12-11 10:37:55 -08001636 writer.print(prefix); writer.println("Loader Manager:");
1637 mLoaderManager.dump(prefix + " ", fd, writer, args);
Dianne Hackborn625ac272010-09-17 18:29:22 -07001638 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001639 if (mChildFragmentManager != null) {
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001640 writer.print(prefix); writer.println("Child " + mChildFragmentManager + ":");
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001641 mChildFragmentManager.dump(prefix + " ", fd, writer, args);
1642 }
1643 }
1644
1645 Fragment findFragmentByWho(String who) {
1646 if (who.equals(mWho)) {
1647 return this;
1648 }
1649 if (mChildFragmentManager != null) {
1650 return mChildFragmentManager.findFragmentByWho(who);
1651 }
1652 return null;
1653 }
1654
1655 void instantiateChildFragmentManager() {
1656 mChildFragmentManager = new FragmentManagerImpl();
1657 mChildFragmentManager.attachActivity(mActivity, new FragmentContainer() {
1658 @Override
1659 public View findViewById(int id) {
1660 if (mView == null) {
1661 throw new IllegalStateException("Fragment does not have a view");
1662 }
1663 return mView.findViewById(id);
1664 }
1665 }, this);
1666 }
1667
1668 void performCreate(Bundle savedInstanceState) {
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001669 if (mChildFragmentManager != null) {
1670 mChildFragmentManager.noteStateNotSaved();
1671 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001672 mCalled = false;
1673 onCreate(savedInstanceState);
1674 if (!mCalled) {
1675 throw new SuperNotCalledException("Fragment " + this
1676 + " did not call through to super.onCreate()");
1677 }
1678 if (savedInstanceState != null) {
1679 Parcelable p = savedInstanceState.getParcelable(Activity.FRAGMENTS_TAG);
1680 if (p != null) {
1681 if (mChildFragmentManager == null) {
1682 instantiateChildFragmentManager();
1683 }
1684 mChildFragmentManager.restoreAllState(p, null);
1685 mChildFragmentManager.dispatchCreate();
1686 }
1687 }
1688 }
1689
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001690 View performCreateView(LayoutInflater inflater, ViewGroup container,
1691 Bundle savedInstanceState) {
1692 if (mChildFragmentManager != null) {
1693 mChildFragmentManager.noteStateNotSaved();
1694 }
1695 return onCreateView(inflater, container, savedInstanceState);
1696 }
1697
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001698 void performActivityCreated(Bundle savedInstanceState) {
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001699 if (mChildFragmentManager != null) {
1700 mChildFragmentManager.noteStateNotSaved();
1701 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001702 mCalled = false;
1703 onActivityCreated(savedInstanceState);
1704 if (!mCalled) {
1705 throw new SuperNotCalledException("Fragment " + this
1706 + " did not call through to super.onActivityCreated()");
1707 }
1708 if (mChildFragmentManager != null) {
1709 mChildFragmentManager.dispatchActivityCreated();
1710 }
Dianne Hackborn625ac272010-09-17 18:29:22 -07001711 }
1712
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001713 void performStart() {
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001714 if (mChildFragmentManager != null) {
1715 mChildFragmentManager.noteStateNotSaved();
1716 mChildFragmentManager.execPendingActions();
1717 }
1718 mCalled = false;
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001719 onStart();
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001720 if (!mCalled) {
1721 throw new SuperNotCalledException("Fragment " + this
1722 + " did not call through to super.onStart()");
1723 }
1724 if (mChildFragmentManager != null) {
1725 mChildFragmentManager.dispatchStart();
1726 }
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001727 if (mLoaderManager != null) {
1728 mLoaderManager.doReportStart();
1729 }
1730 }
1731
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001732 void performResume() {
1733 if (mChildFragmentManager != null) {
Dianne Hackborn1b8ecc52012-09-08 17:03:52 -07001734 mChildFragmentManager.noteStateNotSaved();
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001735 mChildFragmentManager.execPendingActions();
1736 }
1737 mCalled = false;
1738 onResume();
1739 if (!mCalled) {
1740 throw new SuperNotCalledException("Fragment " + this
1741 + " did not call through to super.onResume()");
1742 }
1743 if (mChildFragmentManager != null) {
1744 mChildFragmentManager.dispatchResume();
1745 mChildFragmentManager.execPendingActions();
1746 }
1747 }
1748
1749 void performConfigurationChanged(Configuration newConfig) {
1750 onConfigurationChanged(newConfig);
1751 if (mChildFragmentManager != null) {
1752 mChildFragmentManager.dispatchConfigurationChanged(newConfig);
1753 }
1754 }
1755
1756 void performLowMemory() {
1757 onLowMemory();
1758 if (mChildFragmentManager != null) {
1759 mChildFragmentManager.dispatchLowMemory();
1760 }
1761 }
1762
1763 void performTrimMemory(int level) {
1764 onTrimMemory(level);
1765 if (mChildFragmentManager != null) {
1766 mChildFragmentManager.dispatchTrimMemory(level);
1767 }
1768 }
1769
1770 boolean performCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1771 boolean show = false;
1772 if (!mHidden) {
1773 if (mHasMenu && mMenuVisible) {
1774 show = true;
1775 onCreateOptionsMenu(menu, inflater);
1776 }
1777 if (mChildFragmentManager != null) {
1778 show |= mChildFragmentManager.dispatchCreateOptionsMenu(menu, inflater);
1779 }
1780 }
1781 return show;
1782 }
1783
1784 boolean performPrepareOptionsMenu(Menu menu) {
1785 boolean show = false;
1786 if (!mHidden) {
1787 if (mHasMenu && mMenuVisible) {
1788 show = true;
1789 onPrepareOptionsMenu(menu);
1790 }
1791 if (mChildFragmentManager != null) {
1792 show |= mChildFragmentManager.dispatchPrepareOptionsMenu(menu);
1793 }
1794 }
1795 return show;
1796 }
1797
1798 boolean performOptionsItemSelected(MenuItem item) {
1799 if (!mHidden) {
1800 if (mHasMenu && mMenuVisible) {
1801 if (onOptionsItemSelected(item)) {
1802 return true;
1803 }
1804 }
1805 if (mChildFragmentManager != null) {
1806 if (mChildFragmentManager.dispatchOptionsItemSelected(item)) {
1807 return true;
1808 }
1809 }
1810 }
1811 return false;
1812 }
1813
1814 boolean performContextItemSelected(MenuItem item) {
1815 if (!mHidden) {
1816 if (onContextItemSelected(item)) {
1817 return true;
1818 }
1819 if (mChildFragmentManager != null) {
1820 if (mChildFragmentManager.dispatchContextItemSelected(item)) {
1821 return true;
1822 }
1823 }
1824 }
1825 return false;
1826 }
1827
1828 void performOptionsMenuClosed(Menu menu) {
1829 if (!mHidden) {
1830 if (mHasMenu && mMenuVisible) {
1831 onOptionsMenuClosed(menu);
1832 }
1833 if (mChildFragmentManager != null) {
1834 mChildFragmentManager.dispatchOptionsMenuClosed(menu);
1835 }
1836 }
1837 }
1838
1839 void performSaveInstanceState(Bundle outState) {
1840 onSaveInstanceState(outState);
1841 if (mChildFragmentManager != null) {
1842 Parcelable p = mChildFragmentManager.saveAllState();
1843 if (p != null) {
1844 outState.putParcelable(Activity.FRAGMENTS_TAG, p);
1845 }
1846 }
1847 }
1848
1849 void performPause() {
1850 if (mChildFragmentManager != null) {
1851 mChildFragmentManager.dispatchPause();
1852 }
1853 mCalled = false;
1854 onPause();
1855 if (!mCalled) {
1856 throw new SuperNotCalledException("Fragment " + this
1857 + " did not call through to super.onPause()");
1858 }
1859 }
1860
Dianne Hackborn2707d602010-07-09 18:01:20 -07001861 void performStop() {
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001862 if (mChildFragmentManager != null) {
1863 mChildFragmentManager.dispatchStop();
1864 }
1865 mCalled = false;
Dianne Hackborn2707d602010-07-09 18:01:20 -07001866 onStop();
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001867 if (!mCalled) {
1868 throw new SuperNotCalledException("Fragment " + this
1869 + " did not call through to super.onStop()");
1870 }
Dianne Hackbornfb3cffe2010-10-25 17:08:56 -07001871
1872 if (mLoadersStarted) {
1873 mLoadersStarted = false;
Dianne Hackborn5e0d5952010-08-05 13:45:35 -07001874 if (!mCheckedForLoaderManager) {
1875 mCheckedForLoaderManager = true;
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001876 mLoaderManager = mActivity.getLoaderManager(mWho, mLoadersStarted, false);
Dianne Hackborn5e0d5952010-08-05 13:45:35 -07001877 }
Dianne Hackborn2707d602010-07-09 18:01:20 -07001878 if (mLoaderManager != null) {
1879 if (mActivity == null || !mActivity.mChangingConfigurations) {
1880 mLoaderManager.doStop();
1881 } else {
1882 mLoaderManager.doRetain();
1883 }
1884 }
1885 }
1886 }
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001887
1888 void performDestroyView() {
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001889 if (mChildFragmentManager != null) {
1890 mChildFragmentManager.dispatchDestroyView();
1891 }
1892 mCalled = false;
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001893 onDestroyView();
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001894 if (!mCalled) {
1895 throw new SuperNotCalledException("Fragment " + this
1896 + " did not call through to super.onDestroyView()");
1897 }
Dianne Hackbornafc4b282011-06-10 17:03:42 -07001898 if (mLoaderManager != null) {
1899 mLoaderManager.doReportNextStart();
1900 }
1901 }
Dianne Hackborn62bea2f2012-09-04 18:48:15 -07001902
1903 void performDestroy() {
1904 if (mChildFragmentManager != null) {
1905 mChildFragmentManager.dispatchDestroy();
1906 }
1907 mCalled = false;
1908 onDestroy();
1909 if (!mCalled) {
1910 throw new SuperNotCalledException("Fragment " + this
1911 + " did not call through to super.onDestroy()");
1912 }
1913 }
Dianne Hackborn2dedce62010-04-15 14:45:25 -07001914}