diff options
Diffstat (limited to 'core/java/android/app/FragmentManager.java')
-rw-r--r-- | core/java/android/app/FragmentManager.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 3da4f29..58cd27c 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -709,6 +709,13 @@ final class FragmentManagerImpl extends FragmentManager { return AnimatorInflater.loadAnimator(mActivity, anim); } + public void performPendingDeferredStart(Fragment f) { + if (f.mDeferStart) { + f.mDeferStart = false; + moveToState(f, mCurState, 0, 0); + } + } + void moveToState(Fragment f, int newState, int transit, int transitionStyle) { // Fragments that are not currently added will sit in the onCreate() state. if (!f.mAdded && newState > Fragment.CREATED) { @@ -718,7 +725,10 @@ final class FragmentManagerImpl extends FragmentManager { // While removing a fragment, we can't change it to a higher state. newState = f.mState; } - + // Defer start if requested; don't allow it to move to STARTED or higher. + if (f.mDeferStart && newState > Fragment.STOPPED) { + newState = Fragment.STOPPED; + } if (f.mState < newState) { // For fragments that are created from a layout, when restoring from // state we don't want to allow them to be created until they are @@ -992,13 +1002,21 @@ final class FragmentManagerImpl extends FragmentManager { mCurState = newState; if (mActive != null) { + boolean loadersRunning = false; for (int i=0; i<mActive.size(); i++) { Fragment f = mActive.get(i); if (f != null) { moveToState(f, newState, transit, transitStyle); + if (f.mLoaderManager != null) { + loadersRunning |= f.mLoaderManager.hasRunningLoaders(); + } } } + if (!loadersRunning) { + startPendingDeferredFragments(); + } + if (mNeedMenuInvalidate && mActivity != null && mCurState == Fragment.RESUMED) { mActivity.invalidateOptionsMenu(); mNeedMenuInvalidate = false; @@ -1006,6 +1024,15 @@ final class FragmentManagerImpl extends FragmentManager { } } + void startPendingDeferredFragments() { + for (int i=0; i<mActive.size(); i++) { + Fragment f = mActive.get(i); + if (f != null) { + performPendingDeferredStart(f); + } + } + } + void makeActive(Fragment f) { if (f.mIndex >= 0) { return; |