Fragment.java revision 4911b783aa9f4af5ac919db861751d350471f5ef
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.content.ComponentCallbacks;
20import android.content.Intent;
21import android.content.res.Configuration;
22import android.os.Bundle;
23import android.os.Parcel;
24import android.os.Parcelable;
25import android.util.AttributeSet;
26import android.util.SparseArray;
27import android.view.ContextMenu;
28import android.view.LayoutInflater;
29import android.view.Menu;
30import android.view.MenuInflater;
31import android.view.MenuItem;
32import android.view.View;
33import android.view.ViewGroup;
34import android.view.ContextMenu.ContextMenuInfo;
35import android.view.View.OnCreateContextMenuListener;
36import android.view.animation.Animation;
37import android.widget.AdapterView;
38
39import java.lang.reflect.InvocationTargetException;
40import java.util.HashMap;
41
42final class FragmentState implements Parcelable {
43    static final String VIEW_STATE_TAG = "android:view_state";
44
45    final String mClassName;
46    final int mIndex;
47    final boolean mFromLayout;
48    final int mFragmentId;
49    final int mContainerId;
50    final String mTag;
51    final boolean mRetainInstance;
52
53    Bundle mSavedFragmentState;
54
55    Fragment mInstance;
56
57    public FragmentState(Fragment frag) {
58        mClassName = frag.getClass().getName();
59        mIndex = frag.mIndex;
60        mFromLayout = frag.mFromLayout;
61        mFragmentId = frag.mFragmentId;
62        mContainerId = frag.mContainerId;
63        mTag = frag.mTag;
64        mRetainInstance = frag.mRetainInstance;
65    }
66
67    public FragmentState(Parcel in) {
68        mClassName = in.readString();
69        mIndex = in.readInt();
70        mFromLayout = in.readInt() != 0;
71        mFragmentId = in.readInt();
72        mContainerId = in.readInt();
73        mTag = in.readString();
74        mRetainInstance = in.readInt() != 0;
75        mSavedFragmentState = in.readBundle();
76    }
77
78    public Fragment instantiate(Activity activity) {
79        if (mInstance != null) {
80            return mInstance;
81        }
82
83        try {
84            mInstance = Fragment.instantiate(activity, mClassName);
85        } catch (Exception e) {
86            throw new RuntimeException("Unable to restore fragment " + mClassName, e);
87        }
88
89        if (mSavedFragmentState != null) {
90            mSavedFragmentState.setClassLoader(activity.getClassLoader());
91            mInstance.mSavedFragmentState = mSavedFragmentState;
92            mInstance.mSavedViewState
93                    = mSavedFragmentState.getSparseParcelableArray(VIEW_STATE_TAG);
94        }
95        mInstance.setIndex(mIndex);
96        mInstance.mFromLayout = mFromLayout;
97        mInstance.mFragmentId = mFragmentId;
98        mInstance.mContainerId = mContainerId;
99        mInstance.mTag = mTag;
100        mInstance.mRetainInstance = mRetainInstance;
101
102        return mInstance;
103    }
104
105    public int describeContents() {
106        return 0;
107    }
108
109    public void writeToParcel(Parcel dest, int flags) {
110        dest.writeString(mClassName);
111        dest.writeInt(mIndex);
112        dest.writeInt(mFromLayout ? 1 : 0);
113        dest.writeInt(mFragmentId);
114        dest.writeInt(mContainerId);
115        dest.writeString(mTag);
116        dest.writeInt(mRetainInstance ? 1 : 0);
117        dest.writeBundle(mSavedFragmentState);
118    }
119
120    public static final Parcelable.Creator<FragmentState> CREATOR
121            = new Parcelable.Creator<FragmentState>() {
122        public FragmentState createFromParcel(Parcel in) {
123            return new FragmentState(in);
124        }
125
126        public FragmentState[] newArray(int size) {
127            return new FragmentState[size];
128        }
129    };
130}
131
132/**
133 * A Fragment is a piece of an application's user interface or behavior
134 * that can be placed in an {@link Activity}.
135 */
136public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener {
137    private static final HashMap<String, Class<?>> sClassMap =
138            new HashMap<String, Class<?>>();
139
140    static final int INITIALIZING = 0;     // Not yet created.
141    static final int CREATED = 1;          // Created.
142    static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
143    static final int STARTED = 3;          // Created and started, not resumed.
144    static final int RESUMED = 4;          // Created started and resumed.
145
146    int mState = INITIALIZING;
147
148    // When instantiated from saved state, this is the saved state.
149    Bundle mSavedFragmentState;
150    SparseArray<Parcelable> mSavedViewState;
151
152    // Index into active fragment array.
153    int mIndex = -1;
154
155    // Internal unique name for this fragment;
156    String mWho;
157
158    // True if the fragment is in the list of added fragments.
159    boolean mAdded;
160
161    // True if the fragment is in the resumed state.
162    boolean mResumed;
163
164    // Set to true if this fragment was instantiated from a layout file.
165    boolean mFromLayout;
166
167    // Number of active back stack entries this fragment is in.
168    int mBackStackNesting;
169
170    // Set as soon as a fragment is added to a transaction (or removed),
171    // to be able to do validation.
172    Activity mImmediateActivity;
173
174    // Activity this fragment is attached to.
175    Activity mActivity;
176
177    // The optional identifier for this fragment -- either the container ID if it
178    // was dynamically added to the view hierarchy, or the ID supplied in
179    // layout.
180    int mFragmentId;
181
182    // When a fragment is being dynamically added to the view hierarchy, this
183    // is the identifier of the parent container it is being added to.
184    int mContainerId;
185
186    // The optional named tag for this fragment -- usually used to find
187    // fragments that are not part of the layout.
188    String mTag;
189
190    // Set to true when the app has requested that this fragment be hidden
191    // from the user.
192    boolean mHidden;
193
194    // If set this fragment would like its instance retained across
195    // configuration changes.
196    boolean mRetainInstance;
197
198    // If set this fragment is being retained across the current config change.
199    boolean mRetaining;
200
201    // If set this fragment has menu items to contribute.
202    boolean mHasMenu;
203
204    // Used to verify that subclasses call through to super class.
205    boolean mCalled;
206
207    // If app has requested a specific animation, this is the one to use.
208    int mNextAnim;
209
210    // The parent container of the fragment after dynamically added to UI.
211    ViewGroup mContainer;
212
213    // The View generated for this fragment.
214    View mView;
215
216    LoaderManagerImpl mLoaderManager;
217    boolean mStarted;
218
219    /**
220     * Default constructor.  <strong>Every</string> fragment must have an
221     * empty constructor, so it can be instantiated when restoring its
222     * activity's state.  It is strongly recommended that subclasses do not
223     * have other constructors with parameters, since these constructors
224     * will not be called when the fragment is re-instantiated; instead,
225     * retrieve such parameters from the activity in {@link #onAttach(Activity)}.
226     */
227    public Fragment() {
228    }
229
230    static Fragment instantiate(Activity activity, String fname)
231            throws NoSuchMethodException, ClassNotFoundException,
232            IllegalArgumentException, InstantiationException,
233            IllegalAccessException, InvocationTargetException {
234        Class<?> clazz = sClassMap.get(fname);
235
236        if (clazz == null) {
237            // Class not found in the cache, see if it's real, and try to add it
238            clazz = activity.getClassLoader().loadClass(fname);
239            sClassMap.put(fname, clazz);
240        }
241        return (Fragment)clazz.newInstance();
242    }
243
244    void restoreViewState() {
245        if (mSavedViewState != null) {
246            mView.restoreHierarchyState(mSavedViewState);
247            mSavedViewState = null;
248        }
249    }
250
251    void setIndex(int index) {
252        mIndex = index;
253        mWho = "android:fragment:" + mIndex;
254   }
255
256    void clearIndex() {
257        mIndex = -1;
258        mWho = null;
259    }
260
261    /**
262     * Subclasses can not override equals().
263     */
264    @Override final public boolean equals(Object o) {
265        return super.equals(o);
266    }
267
268    /**
269     * Subclasses can not override hashCode().
270     */
271    @Override final public int hashCode() {
272        return super.hashCode();
273    }
274
275    @Override
276    public String toString() {
277        StringBuilder sb = new StringBuilder(128);
278        sb.append("Fragment{");
279        sb.append(Integer.toHexString(System.identityHashCode(this)));
280        if (mIndex >= 0) {
281            sb.append(" #");
282            sb.append(mIndex);
283        }
284        if (mFragmentId != 0) {
285            sb.append(" id=0x");
286            sb.append(Integer.toHexString(mFragmentId));
287        }
288        if (mTag != null) {
289            sb.append(" ");
290            sb.append(mTag);
291        }
292        sb.append('}');
293        return sb.toString();
294    }
295
296    /**
297     * Return the identifier this fragment is known by.  This is either
298     * the android:id value supplied in a layout or the container view ID
299     * supplied when adding the fragment.
300     */
301    final public int getId() {
302        return mFragmentId;
303    }
304
305    /**
306     * Get the tag name of the fragment, if specified.
307     */
308    final public String getTag() {
309        return mTag;
310    }
311
312    /**
313     * Return the Activity this fragment is currently associated with.
314     */
315    final public Activity getActivity() {
316        return mActivity;
317    }
318
319    /**
320     * Return true if the fragment is currently added to its activity.
321     */
322    final public boolean isAdded() {
323        return mActivity != null && mActivity.mFragments.mAdded.contains(this);
324    }
325
326    /**
327     * Return true if the fragment is in the resumed state.  This is true
328     * for the duration of {@link #onResume()} and {@link #onPause()} as well.
329     */
330    final public boolean isResumed() {
331        return mResumed;
332    }
333
334    /**
335     * Return true if the fragment is currently visible to the user.  This means
336     * it: (1) has been added, (2) has its view attached to the window, and
337     * (3) is not hidden.
338     */
339    final public boolean isVisible() {
340        return isAdded() && !isHidden() && mView != null
341                && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
342    }
343
344    /**
345     * Return true if the fragment has been hidden.  By default fragments
346     * are shown.  You can find out about changes to this state with
347     * {@link #onHiddenChanged}.  Note that the hidden state is orthogonal
348     * to other states -- that is, to be visible to the user, a fragment
349     * must be both started and not hidden.
350     */
351    final public boolean isHidden() {
352        return mHidden;
353    }
354
355    /**
356     * Called when the hidden state (as returned by {@link #isHidden()} of
357     * the fragment has changed.  Fragments start out not hidden; this will
358     * be called whenever the fragment changes state from that.
359     * @param hidden True if the fragment is now hidden, false if it is not
360     * visible.
361     */
362    public void onHiddenChanged(boolean hidden) {
363    }
364
365    /**
366     * Control whether a fragment instance is retained across Activity
367     * re-creation (such as from a configuration change).  This can only
368     * be used with fragments not in the back stack.  If set, the fragment
369     * lifecycle will be slightly different when an activity is recreated:
370     * <ul>
371     * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
372     * will be, because the fragment is being detached from its current activity).
373     * <li> {@link #onCreate(Bundle)} will not be called since the fragment
374     * is not being re-created.
375     * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
376     * still be called.
377     * </ul>
378     */
379    public void setRetainInstance(boolean retain) {
380        mRetainInstance = retain;
381    }
382
383    final public boolean getRetainInstance() {
384        return mRetainInstance;
385    }
386
387    /**
388     * Report that this fragment would like to participate in populating
389     * the options menu by receiving a call to {@link #onCreateOptionsMenu}
390     * and related methods.
391     *
392     * @param hasMenu If true, the fragment has menu items to contribute.
393     */
394    public void setHasOptionsMenu(boolean hasMenu) {
395        if (mHasMenu != hasMenu) {
396            mHasMenu = hasMenu;
397            if (isAdded() && !isHidden()) {
398                mActivity.invalidateOptionsMenu();
399            }
400        }
401    }
402
403    /**
404     * Return the LoaderManager for this fragment, creating it if needed.
405     */
406    public LoaderManager getLoaderManager() {
407        if (mLoaderManager != null) {
408            return mLoaderManager;
409        }
410        mLoaderManager = mActivity.getLoaderManager(mIndex, mStarted);
411        return mLoaderManager;
412    }
413
414    /**
415     * Call {@link Activity#startActivity(Intent)} on the fragment's
416     * containing Activity.
417     */
418    public void startActivity(Intent intent) {
419        mActivity.startActivityFromFragment(this, intent, -1);
420    }
421
422    /**
423     * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's
424     * containing Activity.
425     */
426    public void startActivityForResult(Intent intent, int requestCode) {
427        mActivity.startActivityFromFragment(this, intent, requestCode);
428    }
429
430    /**
431     * Receive the result from a previous call to
432     * {@link #startActivityForResult(Intent, int)}.  This follows the
433     * related Activity API as described there in
434     * {@link Activity#onActivityResult(int, int, Intent)}.
435     *
436     * @param requestCode The integer request code originally supplied to
437     *                    startActivityForResult(), allowing you to identify who this
438     *                    result came from.
439     * @param resultCode The integer result code returned by the child activity
440     *                   through its setResult().
441     * @param data An Intent, which can return result data to the caller
442     *               (various data can be attached to Intent "extras").
443     */
444    public void onActivityResult(int requestCode, int resultCode, Intent data) {
445    }
446
447    /**
448     * Called when a fragment is being created as part of a view layout
449     * inflation, typically from setting the content view of an activity.  This
450     * will be called both the first time the fragment is created, as well
451     * later when it is being re-created from its saved state (which is also
452     * given here).
453     *
454     * XXX This is kind-of yucky...  maybe we could just supply the
455     * AttributeSet to onCreate()?
456     *
457     * @param activity The Activity that is inflating the fragment.
458     * @param attrs The attributes at the tag where the fragment is
459     * being created.
460     * @param savedInstanceState If the fragment is being re-created from
461     * a previous saved state, this is the state.
462     */
463    public void onInflate(Activity activity, AttributeSet attrs,
464            Bundle savedInstanceState) {
465        mCalled = true;
466    }
467
468    /**
469     * Called when a fragment is first attached to its activity.
470     * {@link #onCreate(Bundle)} will be called after this.
471     */
472    public void onAttach(Activity activity) {
473        mCalled = true;
474    }
475
476    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
477        return null;
478    }
479
480    /**
481     * Called to do initial creation of a fragment.  This is called after
482     * {@link #onAttach(Activity)} and before
483     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
484     *
485     * <p>Note that this can be called while the fragment's activity is
486     * still in the process of being created.  As such, you can not rely
487     * on things like the activity's content view hierarchy being initialized
488     * at this point.  If you want to do work once the activity itself is
489     * created, see {@link #onActivityCreated(Bundle)}.
490     *
491     * @param savedInstanceState If the fragment is being re-created from
492     * a previous saved state, this is the state.
493     */
494    public void onCreate(Bundle savedInstanceState) {
495        mCalled = true;
496    }
497
498    /**
499     * Called to have the fragment instantiate its user interface view.
500     * This is optional, and non-graphical fragments can return null (which
501     * is the default implementation).  This will be called between
502     * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
503     *
504     * <p>If you return a View from here, you will later be called in
505     * {@link #onDestroyView} when the view is being released.
506     *
507     * @param inflater The LayoutInflater object that can be used to inflate
508     * any views in the fragment,
509     * @param container If non-null, this is the parent view that the fragment's
510     * UI should be attached to.  The fragment should not add the view itself,
511     * but this can be used to generate the LayoutParams of the view.
512     * @param savedInstanceState If non-null, this fragment is being re-constructed
513     * from a previous saved state as given here.
514     *
515     * @return Return the View for the fragment's UI, or null.
516     */
517    public View onCreateView(LayoutInflater inflater, ViewGroup container,
518            Bundle savedInstanceState) {
519        return null;
520    }
521
522    public View getView() {
523        return mView;
524    }
525
526    /**
527     * Called when the fragment's activity has been created and this
528     * fragment's view hierarchy instantiated.  It can be used to do final
529     * initialization once these pieces are in place, such as retrieving
530     * views or restoring state.  It is also useful for fragments that use
531     * {@link #setRetainInstance(boolean)} to retain their instance,
532     * as this callback tells the fragment when it is fully associated with
533     * the new activity instance.  This is called after {@link #onCreateView}
534     * and before {@link #onStart()}.
535     *
536     * @param savedInstanceState If the fragment is being re-created from
537     * a previous saved state, this is the state.
538     */
539    public void onActivityCreated(Bundle savedInstanceState) {
540        mCalled = true;
541    }
542
543    /**
544     * Called when the Fragment is visible to the user.  This is generally
545     * tied to {@link Activity#onStart() Activity.onStart} of the containing
546     * Activity's lifecycle.
547     */
548    public void onStart() {
549        mCalled = true;
550        mStarted = true;
551        if (mLoaderManager != null) {
552            mLoaderManager.doStart();
553        }
554    }
555
556    /**
557     * Called when the fragment is visible to the user and actively running.
558     * This is generally
559     * tied to {@link Activity#onResume() Activity.onResume} of the containing
560     * Activity's lifecycle.
561     */
562    public void onResume() {
563        mCalled = true;
564    }
565
566    public void onSaveInstanceState(Bundle outState) {
567    }
568
569    public void onConfigurationChanged(Configuration newConfig) {
570        mCalled = true;
571    }
572
573    /**
574     * Called when the Fragment is no longer resumed.  This is generally
575     * tied to {@link Activity#onPause() Activity.onPause} of the containing
576     * Activity's lifecycle.
577     */
578    public void onPause() {
579        mCalled = true;
580    }
581
582    /**
583     * Called when the Fragment is no longer started.  This is generally
584     * tied to {@link Activity#onStop() Activity.onStop} of the containing
585     * Activity's lifecycle.
586     */
587    public void onStop() {
588        mCalled = true;
589    }
590
591    public void onLowMemory() {
592        mCalled = true;
593    }
594
595    /**
596     * Called when the view previously created by {@link #onCreateView} has
597     * been detached from the fragment.  The next time the fragment needs
598     * to be displayed, a new view will be created.  This is called
599     * after {@link #onStop()} and before {@link #onDestroy()}; it is only
600     * called if {@link #onCreateView} returns a non-null View.
601     */
602    public void onDestroyView() {
603        mCalled = true;
604    }
605
606    /**
607     * Called when the fragment is no longer in use.  This is called
608     * after {@link #onStop()} and before {@link #onDetach()}.
609     */
610    public void onDestroy() {
611        mCalled = true;
612        if (mLoaderManager != null) {
613            mLoaderManager.doDestroy();
614        }
615    }
616
617    /**
618     * Called when the fragment is no longer attached to its activity.  This
619     * is called after {@link #onDestroy()}.
620     */
621    public void onDetach() {
622        mCalled = true;
623    }
624
625    /**
626     * Initialize the contents of the Activity's standard options menu.  You
627     * should place your menu items in to <var>menu</var>.  For this method
628     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
629     * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
630     * for more information.
631     *
632     * @param menu The options menu in which you place your items.
633     *
634     * @see #setHasOptionsMenu
635     * @see #onPrepareOptionsMenu
636     * @see #onOptionsItemSelected
637     */
638    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
639    }
640
641    /**
642     * Prepare the Screen's standard options menu to be displayed.  This is
643     * called right before the menu is shown, every time it is shown.  You can
644     * use this method to efficiently enable/disable items or otherwise
645     * dynamically modify the contents.  See
646     * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
647     * for more information.
648     *
649     * @param menu The options menu as last shown or first initialized by
650     *             onCreateOptionsMenu().
651     *
652     * @see #setHasOptionsMenu
653     * @see #onCreateOptionsMenu
654     */
655    public void onPrepareOptionsMenu(Menu menu) {
656    }
657
658    /**
659     * This hook is called whenever an item in your options menu is selected.
660     * The default implementation simply returns false to have the normal
661     * processing happen (calling the item's Runnable or sending a message to
662     * its Handler as appropriate).  You can use this method for any items
663     * for which you would like to do processing without those other
664     * facilities.
665     *
666     * <p>Derived classes should call through to the base class for it to
667     * perform the default menu handling.
668     *
669     * @param item The menu item that was selected.
670     *
671     * @return boolean Return false to allow normal menu processing to
672     *         proceed, true to consume it here.
673     *
674     * @see #onCreateOptionsMenu
675     */
676    public boolean onOptionsItemSelected(MenuItem item) {
677        return false;
678    }
679
680    /**
681     * This hook is called whenever the options menu is being closed (either by the user canceling
682     * the menu with the back/menu button, or when an item is selected).
683     *
684     * @param menu The options menu as last shown or first initialized by
685     *             onCreateOptionsMenu().
686     */
687    public void onOptionsMenuClosed(Menu menu) {
688    }
689
690    /**
691     * Called when a context menu for the {@code view} is about to be shown.
692     * Unlike {@link #onCreateOptionsMenu}, this will be called every
693     * time the context menu is about to be shown and should be populated for
694     * the view (or item inside the view for {@link AdapterView} subclasses,
695     * this can be found in the {@code menuInfo})).
696     * <p>
697     * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
698     * item has been selected.
699     * <p>
700     * The default implementation calls up to
701     * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
702     * you can not call this implementation if you don't want that behavior.
703     * <p>
704     * It is not safe to hold onto the context menu after this method returns.
705     * {@inheritDoc}
706     */
707    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
708        getActivity().onCreateContextMenu(menu, v, menuInfo);
709    }
710
711    /**
712     * Registers a context menu to be shown for the given view (multiple views
713     * can show the context menu). This method will set the
714     * {@link OnCreateContextMenuListener} on the view to this fragment, so
715     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
716     * called when it is time to show the context menu.
717     *
718     * @see #unregisterForContextMenu(View)
719     * @param view The view that should show a context menu.
720     */
721    public void registerForContextMenu(View view) {
722        view.setOnCreateContextMenuListener(this);
723    }
724
725    /**
726     * Prevents a context menu to be shown for the given view. This method will
727     * remove the {@link OnCreateContextMenuListener} on the view.
728     *
729     * @see #registerForContextMenu(View)
730     * @param view The view that should stop showing a context menu.
731     */
732    public void unregisterForContextMenu(View view) {
733        view.setOnCreateContextMenuListener(null);
734    }
735
736    /**
737     * This hook is called whenever an item in a context menu is selected. The
738     * default implementation simply returns false to have the normal processing
739     * happen (calling the item's Runnable or sending a message to its Handler
740     * as appropriate). You can use this method for any items for which you
741     * would like to do processing without those other facilities.
742     * <p>
743     * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
744     * View that added this menu item.
745     * <p>
746     * Derived classes should call through to the base class for it to perform
747     * the default menu handling.
748     *
749     * @param item The context menu item that was selected.
750     * @return boolean Return false to allow normal context menu processing to
751     *         proceed, true to consume it here.
752     */
753    public boolean onContextItemSelected(MenuItem item) {
754        return false;
755    }
756
757    void performStop() {
758        onStop();
759        if (mStarted) {
760            mStarted = false;
761            if (mLoaderManager != null) {
762                if (mActivity == null || !mActivity.mChangingConfigurations) {
763                    mLoaderManager.doStop();
764                } else {
765                    mLoaderManager.doRetain();
766                }
767            }
768        }
769    }
770}
771