@@ -339,6 +339,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
339339 private static final HashMap <String , Class <?>> sClassMap =
340340 new HashMap <String , Class <?>>();
341341
342+ static final int INVALID_STATE = -1 ; // Invalid state used as a null value.
342343 static final int INITIALIZING = 0 ; // Not yet created.
343344 static final int CREATED = 1 ; // Created.
344345 static final int ACTIVITY_CREATED = 2 ; // The activity has finished its creation.
@@ -403,7 +404,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
403404 // The fragment manager we are associated with. Set as soon as the
404405 // fragment is used in a transaction; cleared after it has been removed
405406 // from all transactions.
406- FragmentManager mFragmentManager ;
407+ FragmentManagerImpl mFragmentManager ;
407408
408409 // Activity this fragment is attached to.
409410 Activity mActivity ;
@@ -453,6 +454,10 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
453454 // The View generated for this fragment.
454455 View mView ;
455456
457+ // Whether this fragment should defer starting until after other fragments
458+ // have been started and their loaders are finished.
459+ boolean mDeferStart ;
460+
456461 LoaderManagerImpl mLoaderManager ;
457462 boolean mLoadersStarted ;
458463 boolean mCheckedForLoaderManager ;
@@ -909,6 +914,34 @@ public void setMenuVisibility(boolean menuVisible) {
909914 }
910915 }
911916
917+ /**
918+ * Set whether this fragment should enter the started state as normal or if
919+ * start should be deferred until a system-determined convenient time, such
920+ * as after any loaders have completed their work.
921+ *
922+ * <p>This option is not sticky across fragment starts; after a deferred start
923+ * completes this option will be set to false.</p>
924+ *
925+ * @param deferResume true if this fragment can defer its resume until after others
926+ */
927+ public void setStartDeferred (boolean deferResume ) {
928+ if (mDeferStart && !deferResume ) {
929+ mFragmentManager .performPendingDeferredStart (this );
930+ }
931+ mDeferStart = deferResume ;
932+ }
933+
934+ /**
935+ * Returns true if this fragment's move to the started state has been deferred.
936+ * If this returns true it will be started once other fragments' loaders
937+ * have finished running.
938+ *
939+ * @return true if this fragment's start has been deferred.
940+ */
941+ public boolean isStartDeferred () {
942+ return mDeferStart ;
943+ }
944+
912945 /**
913946 * Return the LoaderManager for this fragment, creating it if needed.
914947 */
0 commit comments