Fragment.java revision 16f6e89c2a4bbf73fe15cb2e81c8fec98c7ac831
1/*
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
19import android.animation.Animator;
20import android.content.ComponentCallbacks;
21import android.content.Context;
22import android.content.Intent;
23import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.os.Bundle;
26import android.os.Parcel;
27import android.os.Parcelable;
28import android.util.AndroidRuntimeException;
29import android.util.AttributeSet;
30import android.util.DebugUtils;
31import android.util.SparseArray;
32import android.view.ContextMenu;
33import android.view.LayoutInflater;
34import android.view.Menu;
35import android.view.MenuInflater;
36import android.view.MenuItem;
37import android.view.View;
38import android.view.ViewGroup;
39import android.view.ContextMenu.ContextMenuInfo;
40import android.view.View.OnCreateContextMenuListener;
41import android.widget.AdapterView;
42
43import java.io.FileDescriptor;
44import java.io.PrintWriter;
45import java.util.HashMap;
46
47final class FragmentState implements Parcelable {
48    final String mClassName;
49    final int mIndex;
50    final boolean mFromLayout;
51    final int mFragmentId;
52    final int mContainerId;
53    final String mTag;
54    final boolean mRetainInstance;
55    final boolean mDetached;
56    final Bundle mArguments;
57
58    Bundle mSavedFragmentState;
59
60    Fragment mInstance;
61
62    public FragmentState(Fragment frag) {
63        mClassName = frag.getClass().getName();
64        mIndex = frag.mIndex;
65        mFromLayout = frag.mFromLayout;
66        mFragmentId = frag.mFragmentId;
67        mContainerId = frag.mContainerId;
68        mTag = frag.mTag;
69        mRetainInstance = frag.mRetainInstance;
70        mDetached = frag.mDetached;
71        mArguments = frag.mArguments;
72    }
73
74    public FragmentState(Parcel in) {
75        mClassName = in.readString();
76        mIndex = in.readInt();
77        mFromLayout = in.readInt() != 0;
78        mFragmentId = in.readInt();
79        mContainerId = in.readInt();
80        mTag = in.readString();
81        mRetainInstance = in.readInt() != 0;
82        mDetached = in.readInt() != 0;
83        mArguments = in.readBundle();
84        mSavedFragmentState = in.readBundle();
85    }
86
87    public Fragment instantiate(Activity activity) {
88        if (mInstance != null) {
89            return mInstance;
90        }
91
92        if (mArguments != null) {
93            mArguments.setClassLoader(activity.getClassLoader());
94        }
95
96        mInstance = Fragment.instantiate(activity, mClassName, mArguments);
97
98        if (mSavedFragmentState != null) {
99            mSavedFragmentState.setClassLoader(activity.getClassLoader());
100            mInstance.mSavedFragmentState = mSavedFragmentState;
101        }
102        mInstance.setIndex(mIndex);
103        mInstance.mFromLayout = mFromLayout;
104        mInstance.mRestored = true;
105        mInstance.mFragmentId = mFragmentId;
106        mInstance.mContainerId = mContainerId;
107        mInstance.mTag = mTag;
108        mInstance.mRetainInstance = mRetainInstance;
109        mInstance.mDetached = mDetached;
110        mInstance.mFragmentManager = activity.mFragments;
111
112        return mInstance;
113    }
114
115    public int describeContents() {
116        return 0;
117    }
118
119    public void writeToParcel(Parcel dest, int flags) {
120        dest.writeString(mClassName);
121        dest.writeInt(mIndex);
122        dest.writeInt(mFromLayout ? 1 : 0);
123        dest.writeInt(mFragmentId);
124        dest.writeInt(mContainerId);
125        dest.writeString(mTag);
126        dest.writeInt(mRetainInstance ? 1 : 0);
127        dest.writeInt(mDetached ? 1 : 0);
128        dest.writeBundle(mArguments);
129        dest.writeBundle(mSavedFragmentState);
130    }
131
132    public static final Parcelable.Creator<FragmentState> CREATOR
133            = new Parcelable.Creator<FragmentState>() {
134        public FragmentState createFromParcel(Parcel in) {
135            return new FragmentState(in);
136        }
137
138        public FragmentState[] newArray(int size) {
139            return new FragmentState[size];
140        }
141    };
142}
143
144/**
145 * A Fragment is a piece of an application's user interface or behavior
146 * that can be placed in an {@link Activity}.  Interaction with fragments
147 * is done through {@link FragmentManager}, which can be obtained via
148 * {@link Activity#getFragmentManager() Activity.getFragmentManager()} and
149 * {@link Fragment#getFragmentManager() Fragment.getFragmentManager()}.
150 *
151 * <p>The Fragment class can be used many ways to achieve a wide variety of
152 * results.  It is core, it represents a particular operation or interface
153 * that is running within a larger {@link Activity}.  A Fragment is closely
154 * tied to the Activity it is in, and can not be used apart from one.  Though
155 * Fragment defines its own lifecycle, that lifecycle is dependent on its
156 * activity: if the activity is stopped, no fragments inside of it can be
157 * started; when the activity is destroyed, all fragments will be destroyed.
158 *
159 * <p>All subclasses of Fragment must include a public empty constructor.
160 * The framework will often re-instantiate a fragment class when needed,
161 * in particular during state restore, and needs to be able to find this
162 * constructor to instantiate it.  If the empty constructor is not available,
163 * a runtime exception will occur in some cases during state restore.
164 *
165 * <p>Topics covered here:
166 * <ol>
167 * <li><a href="#Lifecycle">Lifecycle</a>
168 * <li><a href="#Layout">Layout</a>
169 * <li><a href="#BackStack">Back Stack</a>
170 * </ol>
171 *
172 * <a name="Lifecycle"></a>
173 * <h3>Lifecycle</h3>
174 *
175 * <p>Though a Fragment's lifecycle is tied to its owning activity, it has
176 * its own wrinkle on the standard activity lifecycle.  It includes basic
177 * activity lifecycle methods such as {@link #onResume}, but also important
178 * are methods related to interactions with the activity and UI generation.
179 *
180 * <p>The core series of lifecycle methods that are called to bring a fragment
181 * up to resumed state (interacting with the user) are:
182 *
183 * <ol>
184 * <li> {@link #onAttach} called once the fragment is associated with its activity.
185 * <li> {@link #onCreate} called to do initial creation of the fragment.
186 * <li> {@link #onCreateView} creates and returns the view hierarchy associated
187 * with the fragment.
188 * <li> {@link #onActivityCreated} tells the fragment that its activity has
189 * completed its own {@link Activity#onCreate Activity.onCreaate}.
190 * <li> {@link #onStart} makes the fragment visible to the user (based on its
191 * containing activity being started).
192 * <li> {@link #onResume} makes the fragment interacting with the user (based on its
193 * containing activity being resumed).
194 * </ol>
195 *
196 * <p>As a fragment is no longer being used, it goes through a reverse
197 * series of callbacks:
198 *
199 * <ol>
200 * <li> {@link #onPause} fragment is no longer interacting with the user either
201 * because its activity is being paused or a fragment operation is modifying it
202 * in the activity.
203 * <li> {@link #onStop} fragment is no longer visible to the user either
204 * because its activity is being stopped or a fragment operation is modifying it
205 * in the activity.
206 * <li> {@link #onDestroyView} allows the fragment to clean up resources
207 * associated with its View.
208 * <li> {@link #onDestroy} called to do final cleanup of the fragment's state.
209 * <li> {@link #onDetach} called immediately prior to the fragment no longer
210 * being associated with its activity.
211 * </ol>
212 *
213 * <a name="Layout"></a>
214 * <h3>Layout</h3>
215 *
216 * <p>Fragments can be used as part of your application's layout, allowing
217 * you to better modularize your code and more easily adjust your user
218 * interface to the screen it is running on.  As an example, we can look
219 * at a simple program consisting of a list of items, and display of the
220 * details of each item.</p>
221 *
222 * <p>An activity's layout XML can include <code>&lt;fragment&gt;</code> tags
223 * to embed fragment instances inside of the layout.  For example, here is
224 * a simple layout that embeds one fragment:</p>
225 *
226 * {@sample development/samples/ApiDemos/res/layout/fragment_layout.xml layout}
227 *
228 * <p>The layout is installed in the activity in the normal way:</p>
229 *
230 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
231 *      main}
232 *
233 * <p>The titles fragment, showing a list of titles, is fairly simple, relying
234 * on {@link ListFragment} for most of its work.  Note the implementation of
235 * clicking an item: depending on the current activity's layout, it can either
236 * create and display a new fragment to show the details in-place (more about
237 * this later), or start a new activity show the details.</p>
238 *
239 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
240 *      titles}
241 *
242 * <p>The details fragment showing the contents of selected item here just
243 * displays a string of text based on an index of a string array built in to
244 * the app:</p>
245 *
246 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
247 *      details}
248 *
249 * <p>In this case when the user clicks on a title, there is no details
250 * container in the current activity, so the title title fragment's click code will
251 * launch a new activity to display the details fragment:</p>
252 *
253 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
254 *      details_activity}
255 *
256 * <p>However the screen may be large enough to show both the list of titles
257 * and details about the currently selected title.  To use such a layout on
258 * a landscape screen, this alternative layout can be placed under layout-land:</p>
259 *
260 * {@sample development/samples/ApiDemos/res/layout-land/fragment_layout.xml layout}
261 *
262 * <p>Note how the prior code will adjust to this alternative UI flow: the titles
263 * fragment will now embed the details fragment inside of this activity, and the
264 * details activity will finish itself if it is running in a configuration
265 * where the details can be shown in-place.
266 *
267 * <p>When a configuration change causes the activity hosting these fragments
268 * to restart, its new instance may use a different layout that doesn't
269 * include the same fragments as the previous layout.  In this case all of
270 * the previous fragments will still be instantiated and running in the new
271 * instance.  However, any that are no longer associated with a &lt;fragment&gt;
272 * tag in the view hierarchy will not have their content view created
273 * and will return false from {@link #isInLayout}.  (The code here also shows
274 * how you can determine if a fragment placed in a container is no longer
275 * running in a layout with that container and avoid creating its view hierarchy
276 * in that case.)
277 *
278 * <p>The attributes of the &lt;fragment&gt; tag are used to control the
279 * LayoutParams provided when attaching the fragment's view to the parent
280 * container.  They can also be parsed by the fragment in {@link #onInflate}
281 * as parameters.
282 *
283 * <p>The fragment being instantiated must have some kind of unique identifier
284 * so that it can be re-associated with a previous instance if the parent
285 * activity needs to be destroyed and recreated.  This can be provided these
286 * ways:
287 *
288 * <ul>
289 * <li>If nothing is explicitly supplied, the view ID of the container will
290 * be used.
291 * <li><code>android:tag</code> can be used in &lt;fragment&gt; to provide
292 * a specific tag name for the fragment.
293 * <li><code>android:id</code> can be used in &lt;fragment&gt; to provide
294 * a specific identifier for the fragment.
295 * </ul>
296 *
297 * <a name="BackStack"></a>
298 * <h3>Back Stack</h3>
299 *
300 * <p>The transaction in which fragments are modified can be placed on an
301 * internal back-stack of the owning activity.  When the user presses back
302 * in the activity, any transactions on the back stack are popped off before
303 * the activity itself is finished.
304 *
305 * <p>For example, consider this simple fragment that is instantiated with
306 * an integer argument and displays that in a TextView in its UI:</p>
307 *
308 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentStack.java
309 *      fragment}
310 *
311 * <p>A function that creates a new instance of the fragment, replacing
312 * whatever current fragment instance is being shown and pushing that change
313 * on to the back stack could be written as:
314 *
315 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentStack.java
316 *      add_stack}
317 *
318 * <p>After each call to this function, a new entry is on the stack, and
319 * pressing back will pop it to return the user to whatever previous state
320 * the activity UI was in.
321 */
322public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener {
323    private static final HashMap<String, Class<?>> sClassMap =
324            new HashMap<String, Class<?>>();
325
326    static final int INITIALIZING = 0;     // Not yet created.
327    static final int CREATED = 1;          // Created.
328    static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
329    static final int STOPPED = 3;          // Fully created, not started.
330    static final int STARTED = 4;          // Created and started, not resumed.
331    static final int RESUMED = 5;          // Created started and resumed.
332
333    int mState = INITIALIZING;
334
335    // Non-null if the fragment's view hierarchy is currently animating away,
336    // meaning we need to wait a bit on completely destroying it.  This is the
337    // animation that is running.
338    Animator mAnimatingAway;
339
340    // If mAnimatingAway != null, this is the state we should move to once the
341    // animation is done.
342    int mStateAfterAnimating;
343
344    // When instantiated from saved state, this is the saved state.
345    Bundle mSavedFragmentState;
346    SparseArray<Parcelable> mSavedViewState;
347
348    // Index into active fragment array.
349    int mIndex = -1;
350
351    // Internal unique name for this fragment;
352    String mWho;
353
354    // Construction arguments;
355    Bundle mArguments;
356
357    // Target fragment.
358    Fragment mTarget;
359
360    // Target request code.
361    int mTargetRequestCode;
362
363    // True if the fragment is in the list of added fragments.
364    boolean mAdded;
365
366    // If set this fragment is being removed from its activity.
367    boolean mRemoving;
368
369    // True if the fragment is in the resumed state.
370    boolean mResumed;
371
372    // Set to true if this fragment was instantiated from a layout file.
373    boolean mFromLayout;
374
375    // Set to true when the view has actually been inflated in its layout.
376    boolean mInLayout;
377
378    // True if this fragment has been restored from previously saved state.
379    boolean mRestored;
380
381    // Number of active back stack entries this fragment is in.
382    int mBackStackNesting;
383
384    // The fragment manager we are associated with.  Set as soon as the
385    // fragment is used in a transaction; cleared after it has been removed
386    // from all transactions.
387    FragmentManager mFragmentManager;
388
389    // Set as soon as a fragment is added to a transaction (or removed),
390    // to be able to do validation.
391    Activity mImmediateActivity;
392
393    // Activity this fragment is attached to.
394    Activity mActivity;
395
396    // The optional identifier for this fragment -- either the container ID if it
397    // was dynamically added to the view hierarchy, or the ID supplied in
398    // layout.
399    int mFragmentId;
400
401    // When a fragment is being dynamically added to the view hierarchy, this
402    // is the identifier of the parent container it is being added to.
403    int mContainerId;
404
405    // The optional named tag for this fragment -- usually used to find
406    // fragments that are not part of the layout.
407    String mTag;
408
409    // Set to true when the app has requested that this fragment be hidden
410    // from the user.
411    boolean mHidden;
412
413    // Set to true when the app has requested that this fragment be detached.
414    boolean mDetached;
415
416    // If set this fragment would like its instance retained across
417    // configuration changes.
418    boolean mRetainInstance;
419
420    // If set this fragment is being retained across the current config change.
421    boolean mRetaining;
422
423    // If set this fragment has menu items to contribute.
424    boolean mHasMenu;
425
426    // Used to verify that subclasses call through to super class.
427    boolean mCalled;
428
429    // If app has requested a specific animation, this is the one to use.
430    int mNextAnim;
431
432    // The parent container of the fragment after dynamically added to UI.
433    ViewGroup mContainer;
434
435    // The View generated for this fragment.
436    View mView;
437
438    LoaderManagerImpl mLoaderManager;
439    boolean mLoadersStarted;
440    boolean mCheckedForLoaderManager;
441
442    /**
443     * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
444     * there is an instantiation failure.
445     */
446    static public class InstantiationException extends AndroidRuntimeException {
447        public InstantiationException(String msg, Exception cause) {
448            super(msg, cause);
449        }
450    }
451
452    /**
453     * Default constructor.  <strong>Every</strong> fragment must have an
454     * empty constructor, so it can be instantiated when restoring its
455     * activity's state.  It is strongly recommended that subclasses do not
456     * have other constructors with parameters, since these constructors
457     * will not be called when the fragment is re-instantiated; instead,
458     * arguments can be supplied by the caller with {@link #setArguments}
459     * and later retrieved by the Fragment with {@link #getArguments}.
460     *
461     * <p>Applications should generally not implement a constructor.  The
462     * first place application code an run where the fragment is ready to
463     * be used is in {@link #onAttach(Activity)}, the point where the fragment
464     * is actually associated with its activity.  Some applications may also
465     * want to implement {@link #onInflate} to retrieve attributes from a
466     * layout resource, though should take care here because this happens for
467     * the fragment is attached to its activity.
468     */
469    public Fragment() {
470    }
471
472    /**
473     * Like {@link #instantiate(Context, String, Bundle)} but with a null
474     * argument Bundle.
475     */
476    public static Fragment instantiate(Context context, String fname) {
477        return instantiate(context, fname, null);
478    }
479
480    /**
481     * Create a new instance of a Fragment with the given class name.  This is
482     * the same as calling its empty constructor.
483     *
484     * @param context The calling context being used to instantiate the fragment.
485     * This is currently just used to get its ClassLoader.
486     * @param fname The class name of the fragment to instantiate.
487     * @param args Bundle of arguments to supply to the fragment, which it
488     * can retrieve with {@link #getArguments()}.  May be null.
489     * @return Returns a new fragment instance.
490     * @throws InstantiationException If there is a failure in instantiating
491     * the given fragment class.  This is a runtime exception; it is not
492     * normally expected to happen.
493     */
494    public static Fragment instantiate(Context context, String fname, Bundle args) {
495        try {
496            Class<?> clazz = sClassMap.get(fname);
497            if (clazz == null) {
498                // Class not found in the cache, see if it's real, and try to add it
499                clazz = context.getClassLoader().loadClass(fname);
500                sClassMap.put(fname, clazz);
501            }
502            Fragment f = (Fragment)clazz.newInstance();
503            if (args != null) {
504                args.setClassLoader(f.getClass().getClassLoader());
505                f.mArguments = args;
506            }
507            return f;
508        } catch (ClassNotFoundException e) {
509            throw new InstantiationException("Unable to instantiate fragment " + fname
510                    + ": make sure class name exists, is public, and has an"
511                    + " empty constructor that is public", e);
512        } catch (java.lang.InstantiationException e) {
513            throw new InstantiationException("Unable to instantiate fragment " + fname
514                    + ": make sure class name exists, is public, and has an"
515                    + " empty constructor that is public", e);
516        } catch (IllegalAccessException e) {
517            throw new InstantiationException("Unable to instantiate fragment " + fname
518                    + ": make sure class name exists, is public, and has an"
519                    + " empty constructor that is public", e);
520        }
521    }
522
523    final void restoreViewState() {
524        if (mSavedViewState != null) {
525            mView.restoreHierarchyState(mSavedViewState);
526            mSavedViewState = null;
527        }
528    }
529
530    final void setIndex(int index) {
531        mIndex = index;
532        mWho = "android:fragment:" + mIndex;
533   }
534
535    final void clearIndex() {
536        mIndex = -1;
537        mWho = null;
538    }
539
540    final boolean isInBackStack() {
541        return mBackStackNesting > 0;
542    }
543
544    /**
545     * Subclasses can not override equals().
546     */
547    @Override final public boolean equals(Object o) {
548        return super.equals(o);
549    }
550
551    /**
552     * Subclasses can not override hashCode().
553     */
554    @Override final public int hashCode() {
555        return super.hashCode();
556    }
557
558    @Override
559    public String toString() {
560        StringBuilder sb = new StringBuilder(128);
561        DebugUtils.buildShortClassTag(this, sb);
562        if (mIndex >= 0) {
563            sb.append(" #");
564            sb.append(mIndex);
565        }
566        if (mFragmentId != 0) {
567            sb.append(" id=0x");
568            sb.append(Integer.toHexString(mFragmentId));
569        }
570        if (mTag != null) {
571            sb.append(" ");
572            sb.append(mTag);
573        }
574        sb.append('}');
575        return sb.toString();
576    }
577
578    /**
579     * Return the identifier this fragment is known by.  This is either
580     * the android:id value supplied in a layout or the container view ID
581     * supplied when adding the fragment.
582     */
583    final public int getId() {
584        return mFragmentId;
585    }
586
587    /**
588     * Get the tag name of the fragment, if specified.
589     */
590    final public String getTag() {
591        return mTag;
592    }
593
594    /**
595     * Supply the construction arguments for this fragment.  This can only
596     * be called before the fragment has been attached to its activity; that
597     * is, you should call it immediately after constructing the fragment.  The
598     * arguments supplied here will be retained across fragment destroy and
599     * creation.
600     */
601    public void setArguments(Bundle args) {
602        if (mIndex >= 0) {
603            throw new IllegalStateException("Fragment already active");
604        }
605        mArguments = args;
606    }
607
608    /**
609     * Return the arguments supplied when the fragment was instantiated,
610     * if any.
611     */
612    final public Bundle getArguments() {
613        return mArguments;
614    }
615
616    /**
617     * Optional target for this fragment.  This may be used, for example,
618     * if this fragment is being started by another, and when done wants to
619     * give a result back to the first.  The target set here is retained
620     * across instances via {@link FragmentManager#putFragment
621     * FragmentManager.putFragment()}.
622     *
623     * @param fragment The fragment that is the target of this one.
624     * @param requestCode Optional request code, for convenience if you
625     * are going to call back with {@link #onActivityResult(int, int, Intent)}.
626     */
627    public void setTargetFragment(Fragment fragment, int requestCode) {
628        mTarget = fragment;
629        mTargetRequestCode = requestCode;
630    }
631
632    /**
633     * Return the target fragment set by {@link #setTargetFragment}.
634     */
635    final public Fragment getTargetFragment() {
636        return mTarget;
637    }
638
639    /**
640     * Return the target request code set by {@link #setTargetFragment}.
641     */
642    final public int getTargetRequestCode() {
643        return mTargetRequestCode;
644    }
645
646    /**
647     * Return the Activity this fragment is currently associated with.
648     */
649    final public Activity getActivity() {
650        return mActivity;
651    }
652
653    /**
654     * Return <code>getActivity().getResources()</code>.
655     */
656    final public Resources getResources() {
657        if (mActivity == null) {
658            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
659        }
660        return mActivity.getResources();
661    }
662
663    /**
664     * Return a localized, styled CharSequence from the application's package's
665     * default string table.
666     *
667     * @param resId Resource id for the CharSequence text
668     */
669    public final CharSequence getText(int resId) {
670        return getResources().getText(resId);
671    }
672
673    /**
674     * Return a localized string from the application's package's
675     * default string table.
676     *
677     * @param resId Resource id for the string
678     */
679    public final String getString(int resId) {
680        return getResources().getString(resId);
681    }
682
683    /**
684     * Return a localized formatted string from the application's package's
685     * default string table, substituting the format arguments as defined in
686     * {@link java.util.Formatter} and {@link java.lang.String#format}.
687     *
688     * @param resId Resource id for the format string
689     * @param formatArgs The format arguments that will be used for substitution.
690     */
691
692    public final String getString(int resId, Object... formatArgs) {
693        return getResources().getString(resId, formatArgs);
694    }
695
696    /**
697     * Return the FragmentManager for interacting with fragments associated
698     * with this fragment's activity.  Note that this will be non-null slightly
699     * before {@link #getActivity()}, during the time from when the fragment is
700     * placed in a {@link FragmentTransaction} until it is committed and
701     * attached to its activity.
702     */
703    final public FragmentManager getFragmentManager() {
704        return mFragmentManager;
705    }
706
707    /**
708     * Return true if the fragment is currently added to its activity.
709     */
710    final public boolean isAdded() {
711        return mActivity != null && mAdded;
712    }
713
714    /**
715     * Return true if this fragment is currently being removed from its
716     * activity.  This is  <em>not</em> whether its activity is finishing, but
717     * rather whether it is in the process of being removed from its activity.
718     */
719    final public boolean isRemoving() {
720        return mRemoving;
721    }
722
723    /**
724     * Return true if the layout is included as part of an activity view
725     * hierarchy via the &lt;fragment&gt; tag.  This will always be true when
726     * fragments are created through the &lt;fragment&gt; tag, <em>except</em>
727     * in the case where an old fragment is restored from a previous state and
728     * it does not appear in the layout of the current state.
729     */
730    final public boolean isInLayout() {
731        return mInLayout;
732    }
733
734    /**
735     * Return true if the fragment is in the resumed state.  This is true
736     * for the duration of {@link #onResume()} and {@link #onPause()} as well.
737     */
738    final public boolean isResumed() {
739        return mResumed;
740    }
741
742    /**
743     * Return true if the fragment is currently visible to the user.  This means
744     * it: (1) has been added, (2) has its view attached to the window, and
745     * (3) is not hidden.
746     */
747    final public boolean isVisible() {
748        return isAdded() && !isHidden() && mView != null
749                && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
750    }
751
752    /**
753     * Return true if the fragment has been hidden.  By default fragments
754     * are shown.  You can find out about changes to this state with
755     * {@link #onHiddenChanged}.  Note that the hidden state is orthogonal
756     * to other states -- that is, to be visible to the user, a fragment
757     * must be both started and not hidden.
758     */
759    final public boolean isHidden() {
760        return mHidden;
761    }
762
763    /**
764     * Called when the hidden state (as returned by {@link #isHidden()} of
765     * the fragment has changed.  Fragments start out not hidden; this will
766     * be called whenever the fragment changes state from that.
767     * @param hidden True if the fragment is now hidden, false if it is not
768     * visible.
769     */
770    public void onHiddenChanged(boolean hidden) {
771    }
772
773    /**
774     * Control whether a fragment instance is retained across Activity
775     * re-creation (such as from a configuration change).  This can only
776     * be used with fragments not in the back stack.  If set, the fragment
777     * lifecycle will be slightly different when an activity is recreated:
778     * <ul>
779     * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
780     * will be, because the fragment is being detached from its current activity).
781     * <li> {@link #onCreate(Bundle)} will not be called since the fragment
782     * is not being re-created.
783     * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
784     * still be called.
785     * </ul>
786     */
787    public void setRetainInstance(boolean retain) {
788        mRetainInstance = retain;
789    }
790
791    final public boolean getRetainInstance() {
792        return mRetainInstance;
793    }
794
795    /**
796     * Report that this fragment would like to participate in populating
797     * the options menu by receiving a call to {@link #onCreateOptionsMenu}
798     * and related methods.
799     *
800     * @param hasMenu If true, the fragment has menu items to contribute.
801     */
802    public void setHasOptionsMenu(boolean hasMenu) {
803        if (mHasMenu != hasMenu) {
804            mHasMenu = hasMenu;
805            if (isAdded() && !isHidden()) {
806                mActivity.invalidateOptionsMenu();
807            }
808        }
809    }
810
811    /**
812     * Return the LoaderManager for this fragment, creating it if needed.
813     */
814    public LoaderManager getLoaderManager() {
815        if (mLoaderManager != null) {
816            return mLoaderManager;
817        }
818        if (mActivity == null) {
819            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
820        }
821        mCheckedForLoaderManager = true;
822        mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, true);
823        return mLoaderManager;
824    }
825
826    /**
827     * Call {@link Activity#startActivity(Intent)} on the fragment's
828     * containing Activity.
829     */
830    public void startActivity(Intent intent) {
831        if (mActivity == null) {
832            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
833        }
834        mActivity.startActivityFromFragment(this, intent, -1);
835    }
836
837    /**
838     * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's
839     * containing Activity.
840     */
841    public void startActivityForResult(Intent intent, int requestCode) {
842        if (mActivity == null) {
843            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
844        }
845        mActivity.startActivityFromFragment(this, intent, requestCode);
846    }
847
848    /**
849     * Receive the result from a previous call to
850     * {@link #startActivityForResult(Intent, int)}.  This follows the
851     * related Activity API as described there in
852     * {@link Activity#onActivityResult(int, int, Intent)}.
853     *
854     * @param requestCode The integer request code originally supplied to
855     *                    startActivityForResult(), allowing you to identify who this
856     *                    result came from.
857     * @param resultCode The integer result code returned by the child activity
858     *                   through its setResult().
859     * @param data An Intent, which can return result data to the caller
860     *               (various data can be attached to Intent "extras").
861     */
862    public void onActivityResult(int requestCode, int resultCode, Intent data) {
863    }
864
865    /**
866     * @hide Hack so that DialogFragment can make its Dialog before creating
867     * its views, and the view construction can use the dialog's context for
868     * inflation.  Maybe this should become a public API. Note sure.
869     */
870    public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
871        return mActivity.getLayoutInflater();
872    }
873
874    /**
875     * @deprecated Use {@link #onInflate(Activity, AttributeSet, Bundle)} instead.
876     */
877    @Deprecated
878    public void onInflate(AttributeSet attrs, Bundle savedInstanceState) {
879        mCalled = true;
880    }
881
882    /**
883     * Called when a fragment is being created as part of a view layout
884     * inflation, typically from setting the content view of an activity.  This
885     * may be called immediately after the fragment is created from a <fragment>
886     * tag in a layout file.  Note this is <em>before</em> the fragment's
887     * {@link #onAttach(Activity)} has been called; all you should do here is
888     * parse the attributes and save them away.
889     *
890     * <p>This is called every time the fragment is inflated, even if it is
891     * being inflated into a new instance with saved state.  It typically makes
892     * sense to re-parse the parameters each time, to allow them to change with
893     * different configurations.</p>
894     *
895     * <p>Here is a typical implementation of a fragment that can take parameters
896     * both through attributes supplied here as well from {@link #getArguments()}:</p>
897     *
898     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
899     *      fragment}
900     *
901     * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
902     * declaration for the styleable used here is:</p>
903     *
904     * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
905     *
906     * <p>The fragment can then be declared within its activity's content layout
907     * through a tag like this:</p>
908     *
909     * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
910     *
911     * <p>This fragment can also be created dynamically from arguments given
912     * at runtime in the arguments Bundle; here is an example of doing so at
913     * creation of the containing activity:</p>
914     *
915     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
916     *      create}
917     *
918     * @param activity The Activity that is inflating this fragment.
919     * @param attrs The attributes at the tag where the fragment is
920     * being created.
921     * @param savedInstanceState If the fragment is being re-created from
922     * a previous saved state, this is the state.
923     */
924    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
925        onInflate(attrs, savedInstanceState);
926        mCalled = true;
927    }
928
929    /**
930     * Called when a fragment is first attached to its activity.
931     * {@link #onCreate(Bundle)} will be called after this.
932     */
933    public void onAttach(Activity activity) {
934        mCalled = true;
935    }
936
937    /**
938     * Called when a fragment loads an animation.
939     */
940    public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
941        return null;
942    }
943
944    /**
945     * Called to do initial creation of a fragment.  This is called after
946     * {@link #onAttach(Activity)} and before
947     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
948     *
949     * <p>Note that this can be called while the fragment's activity is
950     * still in the process of being created.  As such, you can not rely
951     * on things like the activity's content view hierarchy being initialized
952     * at this point.  If you want to do work once the activity itself is
953     * created, see {@link #onActivityCreated(Bundle)}.
954     *
955     * @param savedInstanceState If the fragment is being re-created from
956     * a previous saved state, this is the state.
957     */
958    public void onCreate(Bundle savedInstanceState) {
959        mCalled = true;
960    }
961
962    /**
963     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
964     * has returned, but before any saved state has been restored in to the view.
965     * This gives subclasses a chance to initialize themselves once
966     * they know their view hierarchy has been completely created.  The fragment's
967     * view hierarchy is not however attached to its parent at this point.
968     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
969     * @param savedInstanceState If non-null, this fragment is being re-constructed
970     * from a previous saved state as given here.
971     */
972    public void onViewCreated(View view, Bundle savedInstanceState) {
973    }
974
975    /**
976     * Called to have the fragment instantiate its user interface view.
977     * This is optional, and non-graphical fragments can return null (which
978     * is the default implementation).  This will be called between
979     * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
980     *
981     * <p>If you return a View from here, you will later be called in
982     * {@link #onDestroyView} when the view is being released.
983     *
984     * @param inflater The LayoutInflater object that can be used to inflate
985     * any views in the fragment,
986     * @param container If non-null, this is the parent view that the fragment's
987     * UI should be attached to.  The fragment should not add the view itself,
988     * but this can be used to generate the LayoutParams of the view.
989     * @param savedInstanceState If non-null, this fragment is being re-constructed
990     * from a previous saved state as given here.
991     *
992     * @return Return the View for the fragment's UI, or null.
993     */
994    public View onCreateView(LayoutInflater inflater, ViewGroup container,
995            Bundle savedInstanceState) {
996        return null;
997    }
998
999    /**
1000     * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
1001     * if provided.
1002     *
1003     * @return The fragment's root view, or null if it has no layout.
1004     */
1005    public View getView() {
1006        return mView;
1007    }
1008
1009    /**
1010     * Called when the fragment's activity has been created and this
1011     * fragment's view hierarchy instantiated.  It can be used to do final
1012     * initialization once these pieces are in place, such as retrieving
1013     * views or restoring state.  It is also useful for fragments that use
1014     * {@link #setRetainInstance(boolean)} to retain their instance,
1015     * as this callback tells the fragment when it is fully associated with
1016     * the new activity instance.  This is called after {@link #onCreateView}
1017     * and before {@link #onStart()}.
1018     *
1019     * @param savedInstanceState If the fragment is being re-created from
1020     * a previous saved state, this is the state.
1021     */
1022    public void onActivityCreated(Bundle savedInstanceState) {
1023        mCalled = true;
1024    }
1025
1026    /**
1027     * Called when the Fragment is visible to the user.  This is generally
1028     * tied to {@link Activity#onStart() Activity.onStart} of the containing
1029     * Activity's lifecycle.
1030     */
1031    public void onStart() {
1032        mCalled = true;
1033
1034        if (!mLoadersStarted) {
1035            mLoadersStarted = true;
1036            if (!mCheckedForLoaderManager) {
1037                mCheckedForLoaderManager = true;
1038                mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false);
1039            }
1040            if (mLoaderManager != null) {
1041                mLoaderManager.doStart();
1042            }
1043        }
1044    }
1045
1046    /**
1047     * Called when the fragment is visible to the user and actively running.
1048     * This is generally
1049     * tied to {@link Activity#onResume() Activity.onResume} of the containing
1050     * Activity's lifecycle.
1051     */
1052    public void onResume() {
1053        mCalled = true;
1054    }
1055
1056    /**
1057     * Called to ask the fragment to save its current dynamic state, so it
1058     * can later be reconstructed in a new instance of its process is
1059     * restarted.  If a new instance of the fragment later needs to be
1060     * created, the data you place in the Bundle here will be available
1061     * in the Bundle given to {@link #onCreate(Bundle)},
1062     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and
1063     * {@link #onActivityCreated(Bundle)}.
1064     *
1065     * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle)
1066     * Activity.onSaveInstanceState(Bundle)} and most of the discussion there
1067     * applies here as well.  Note however: <em>this method may be called
1068     * at any time before {@link #onDestroy()}</em>.  There are many situations
1069     * where a fragment may be mostly torn down (such as when placed on the
1070     * back stack with no UI showing), but its state will not be saved until
1071     * its owning activity actually needs to save its state.
1072     *
1073     * @param outState Bundle in which to place your saved state.
1074     */
1075    public void onSaveInstanceState(Bundle outState) {
1076    }
1077
1078    public void onConfigurationChanged(Configuration newConfig) {
1079        mCalled = true;
1080    }
1081
1082    /**
1083     * Called when the Fragment is no longer resumed.  This is generally
1084     * tied to {@link Activity#onPause() Activity.onPause} of the containing
1085     * Activity's lifecycle.
1086     */
1087    public void onPause() {
1088        mCalled = true;
1089    }
1090
1091    /**
1092     * Called when the Fragment is no longer started.  This is generally
1093     * tied to {@link Activity#onStop() Activity.onStop} of the containing
1094     * Activity's lifecycle.
1095     */
1096    public void onStop() {
1097        mCalled = true;
1098    }
1099
1100    public void onLowMemory() {
1101        mCalled = true;
1102    }
1103
1104    /**
1105     * Called when the view previously created by {@link #onCreateView} has
1106     * been detached from the fragment.  The next time the fragment needs
1107     * to be displayed, a new view will be created.  This is called
1108     * after {@link #onStop()} and before {@link #onDestroy()}.  It is called
1109     * <em>regardless</em> of whether {@link #onCreateView} returned a
1110     * non-null view.  Internally it is called after the view's state has
1111     * been saved but before it has been removed from its parent.
1112     */
1113    public void onDestroyView() {
1114        mCalled = true;
1115    }
1116
1117    /**
1118     * Called when the fragment is no longer in use.  This is called
1119     * after {@link #onStop()} and before {@link #onDetach()}.
1120     */
1121    public void onDestroy() {
1122        mCalled = true;
1123        //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager
1124        //        + " mLoaderManager=" + mLoaderManager);
1125        if (!mCheckedForLoaderManager) {
1126            mCheckedForLoaderManager = true;
1127            mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false);
1128        }
1129        if (mLoaderManager != null) {
1130            mLoaderManager.doDestroy();
1131        }
1132    }
1133
1134    /**
1135     * Called when the fragment is no longer attached to its activity.  This
1136     * is called after {@link #onDestroy()}.
1137     */
1138    public void onDetach() {
1139        mCalled = true;
1140    }
1141
1142    /**
1143     * Initialize the contents of the Activity's standard options menu.  You
1144     * should place your menu items in to <var>menu</var>.  For this method
1145     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
1146     * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
1147     * for more information.
1148     *
1149     * @param menu The options menu in which you place your items.
1150     *
1151     * @see #setHasOptionsMenu
1152     * @see #onPrepareOptionsMenu
1153     * @see #onOptionsItemSelected
1154     */
1155    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1156    }
1157
1158    /**
1159     * Prepare the Screen's standard options menu to be displayed.  This is
1160     * called right before the menu is shown, every time it is shown.  You can
1161     * use this method to efficiently enable/disable items or otherwise
1162     * dynamically modify the contents.  See
1163     * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
1164     * for more information.
1165     *
1166     * @param menu The options menu as last shown or first initialized by
1167     *             onCreateOptionsMenu().
1168     *
1169     * @see #setHasOptionsMenu
1170     * @see #onCreateOptionsMenu
1171     */
1172    public void onPrepareOptionsMenu(Menu menu) {
1173    }
1174
1175    /**
1176     * Called when this fragment's option menu items are no longer being
1177     * included in the overall options menu.  Receiving this call means that
1178     * the menu needed to be rebuilt, but this fragment's items were not
1179     * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)}
1180     * was not called).
1181     */
1182    public void onDestroyOptionsMenu() {
1183    }
1184
1185    /**
1186     * This hook is called whenever an item in your options menu is selected.
1187     * The default implementation simply returns false to have the normal
1188     * processing happen (calling the item's Runnable or sending a message to
1189     * its Handler as appropriate).  You can use this method for any items
1190     * for which you would like to do processing without those other
1191     * facilities.
1192     *
1193     * <p>Derived classes should call through to the base class for it to
1194     * perform the default menu handling.
1195     *
1196     * @param item The menu item that was selected.
1197     *
1198     * @return boolean Return false to allow normal menu processing to
1199     *         proceed, true to consume it here.
1200     *
1201     * @see #onCreateOptionsMenu
1202     */
1203    public boolean onOptionsItemSelected(MenuItem item) {
1204        return false;
1205    }
1206
1207    /**
1208     * This hook is called whenever the options menu is being closed (either by the user canceling
1209     * the menu with the back/menu button, or when an item is selected).
1210     *
1211     * @param menu The options menu as last shown or first initialized by
1212     *             onCreateOptionsMenu().
1213     */
1214    public void onOptionsMenuClosed(Menu menu) {
1215    }
1216
1217    /**
1218     * Called when a context menu for the {@code view} is about to be shown.
1219     * Unlike {@link #onCreateOptionsMenu}, this will be called every
1220     * time the context menu is about to be shown and should be populated for
1221     * the view (or item inside the view for {@link AdapterView} subclasses,
1222     * this can be found in the {@code menuInfo})).
1223     * <p>
1224     * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
1225     * item has been selected.
1226     * <p>
1227     * The default implementation calls up to
1228     * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
1229     * you can not call this implementation if you don't want that behavior.
1230     * <p>
1231     * It is not safe to hold onto the context menu after this method returns.
1232     * {@inheritDoc}
1233     */
1234    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
1235        getActivity().onCreateContextMenu(menu, v, menuInfo);
1236    }
1237
1238    /**
1239     * Registers a context menu to be shown for the given view (multiple views
1240     * can show the context menu). This method will set the
1241     * {@link OnCreateContextMenuListener} on the view to this fragment, so
1242     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
1243     * called when it is time to show the context menu.
1244     *
1245     * @see #unregisterForContextMenu(View)
1246     * @param view The view that should show a context menu.
1247     */
1248    public void registerForContextMenu(View view) {
1249        view.setOnCreateContextMenuListener(this);
1250    }
1251
1252    /**
1253     * Prevents a context menu to be shown for the given view. This method will
1254     * remove the {@link OnCreateContextMenuListener} on the view.
1255     *
1256     * @see #registerForContextMenu(View)
1257     * @param view The view that should stop showing a context menu.
1258     */
1259    public void unregisterForContextMenu(View view) {
1260        view.setOnCreateContextMenuListener(null);
1261    }
1262
1263    /**
1264     * This hook is called whenever an item in a context menu is selected. The
1265     * default implementation simply returns false to have the normal processing
1266     * happen (calling the item's Runnable or sending a message to its Handler
1267     * as appropriate). You can use this method for any items for which you
1268     * would like to do processing without those other facilities.
1269     * <p>
1270     * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
1271     * View that added this menu item.
1272     * <p>
1273     * Derived classes should call through to the base class for it to perform
1274     * the default menu handling.
1275     *
1276     * @param item The context menu item that was selected.
1277     * @return boolean Return false to allow normal context menu processing to
1278     *         proceed, true to consume it here.
1279     */
1280    public boolean onContextItemSelected(MenuItem item) {
1281        return false;
1282    }
1283
1284    /**
1285     * Print the Fragments's state into the given stream.
1286     *
1287     * @param prefix Text to print at the front of each line.
1288     * @param fd The raw file descriptor that the dump is being sent to.
1289     * @param writer The PrintWriter to which you should dump your state.  This will be
1290     * closed for you after you return.
1291     * @param args additional arguments to the dump request.
1292     */
1293    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
1294        writer.print(prefix); writer.print("mFragmentId=#");
1295                writer.print(Integer.toHexString(mFragmentId));
1296                writer.print(" mContainerId#=");
1297                writer.print(Integer.toHexString(mContainerId));
1298                writer.print(" mTag="); writer.println(mTag);
1299        writer.print(prefix); writer.print("mState="); writer.print(mState);
1300                writer.print(" mIndex="); writer.print(mIndex);
1301                writer.print(" mWho="); writer.print(mWho);
1302                writer.print(" mBackStackNesting="); writer.println(mBackStackNesting);
1303        writer.print(prefix); writer.print("mAdded="); writer.print(mAdded);
1304                writer.print(" mRemoving="); writer.print(mRemoving);
1305                writer.print(" mResumed="); writer.print(mResumed);
1306                writer.print(" mFromLayout="); writer.print(mFromLayout);
1307                writer.print(" mInLayout="); writer.println(mInLayout);
1308        writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
1309                writer.print(" mDetached="); writer.print(mDetached);
1310                writer.print(" mRetainInstance="); writer.print(mRetainInstance);
1311                writer.print(" mRetaining="); writer.print(mRetaining);
1312                writer.print(" mHasMenu="); writer.println(mHasMenu);
1313        if (mFragmentManager != null) {
1314            writer.print(prefix); writer.print("mFragmentManager=");
1315                    writer.println(mFragmentManager);
1316        }
1317        if (mImmediateActivity != null) {
1318            writer.print(prefix); writer.print("mImmediateActivity=");
1319                    writer.println(mImmediateActivity);
1320        }
1321        if (mActivity != null) {
1322            writer.print(prefix); writer.print("mActivity=");
1323                    writer.println(mActivity);
1324        }
1325        if (mArguments != null) {
1326            writer.print(prefix); writer.print("mArguments="); writer.println(mArguments);
1327        }
1328        if (mSavedFragmentState != null) {
1329            writer.print(prefix); writer.print("mSavedFragmentState=");
1330                    writer.println(mSavedFragmentState);
1331        }
1332        if (mSavedViewState != null) {
1333            writer.print(prefix); writer.print("mSavedViewState=");
1334                    writer.println(mSavedViewState);
1335        }
1336        if (mTarget != null) {
1337            writer.print(prefix); writer.print("mTarget="); writer.print(mTarget);
1338                    writer.print(" mTargetRequestCode=");
1339                    writer.println(mTargetRequestCode);
1340        }
1341        if (mNextAnim != 0) {
1342            writer.print(prefix); writer.print("mNextAnim="); writer.println(mNextAnim);
1343        }
1344        if (mContainer != null) {
1345            writer.print(prefix); writer.print("mContainer="); writer.println(mContainer);
1346        }
1347        if (mView != null) {
1348            writer.print(prefix); writer.print("mView="); writer.println(mView);
1349        }
1350        if (mAnimatingAway != null) {
1351            writer.print(prefix); writer.print("mAnimatingAway="); writer.println(mAnimatingAway);
1352            writer.print(prefix); writer.print("mStateAfterAnimating=");
1353                    writer.println(mStateAfterAnimating);
1354        }
1355        if (mLoaderManager != null) {
1356            writer.print(prefix); writer.println("Loader Manager:");
1357            mLoaderManager.dump(prefix + "  ", fd, writer, args);
1358        }
1359    }
1360
1361    void performStop() {
1362        onStop();
1363
1364        if (mLoadersStarted) {
1365            mLoadersStarted = false;
1366            if (!mCheckedForLoaderManager) {
1367                mCheckedForLoaderManager = true;
1368                mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false);
1369            }
1370            if (mLoaderManager != null) {
1371                if (mActivity == null || !mActivity.mChangingConfigurations) {
1372                    mLoaderManager.doStop();
1373                } else {
1374                    mLoaderManager.doRetain();
1375                }
1376            }
1377        }
1378    }
1379}
1380