diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-06-05 10:27:40 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-06-05 10:52:38 -0700 |
commit | ee76efb74b5886f98cdfebfbefe9b69224e016fb (patch) | |
tree | 64abbb97bfee90773062d36cb74b1cef5be1cdb1 /core/java/android/app/FragmentManager.java | |
parent | 51df04b93e8e362edd867abd7efaf1659b8b8b82 (diff) | |
download | frameworks_base-ee76efb74b5886f98cdfebfbefe9b69224e016fb.zip frameworks_base-ee76efb74b5886f98cdfebfbefe9b69224e016fb.tar.gz frameworks_base-ee76efb74b5886f98cdfebfbefe9b69224e016fb.tar.bz2 |
Fix issue #6584942 IllegalStateException: Failure saving state...
...active SuggestFragment{419494f0} has cleared index: -1
There were issues when the same fragment was removed and then
added again before completely finishing the remove (such as due
to a running animation).
Two fixes:
- Now when you call FragmentTransaction.replace() and are replacing
a fragment with the same fragment, this becomes a no-op, to avoid
visual artifacts in the transition and bad states.
- When we are moving the fragment state up and it is currently
animating away to the INITIALIZED state, we could end up making
the fragment inactive as part of the cleanup. In this case it
shouldn't be made inactive; we just need to initialize it but
keep it active since we are going to continue to use it.
Bug: 6584942
Change-Id: I8bfd73f2d8ef8f67b541b3e2525dfa5db6c3bfa5
Diffstat (limited to 'core/java/android/app/FragmentManager.java')
-rw-r--r-- | core/java/android/app/FragmentManager.java | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 03ee419..9ba5305 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -726,11 +726,12 @@ final class FragmentManagerImpl extends FragmentManager { return; } f.mDeferStart = false; - moveToState(f, mCurState, 0, 0); + moveToState(f, mCurState, 0, 0, false); } } - void moveToState(Fragment f, int newState, int transit, int transitionStyle) { + void moveToState(Fragment f, int newState, int transit, int transitionStyle, + boolean keepActive) { // Fragments that are not currently added will sit in the onCreate() state. if (!f.mAdded && newState > Fragment.CREATED) { newState = Fragment.CREATED; @@ -757,7 +758,7 @@ final class FragmentManagerImpl extends FragmentManager { // animation, move to whatever the final state should be once // the animation is done, and then we can proceed from there. f.mAnimatingAway = null; - moveToState(f, f.mStateAfterAnimating, 0, 0); + moveToState(f, f.mStateAfterAnimating, 0, 0, true); } switch (f.mState) { case Fragment.INITIALIZING: @@ -940,7 +941,7 @@ final class FragmentManagerImpl extends FragmentManager { if (fragment.mAnimatingAway != null) { fragment.mAnimatingAway = null; moveToState(fragment, fragment.mStateAfterAnimating, - 0, 0); + 0, 0, false); } } }); @@ -992,11 +993,13 @@ final class FragmentManagerImpl extends FragmentManager { throw new SuperNotCalledException("Fragment " + f + " did not call through to super.onDetach()"); } - if (!f.mRetaining) { - makeInactive(f); - } else { - f.mActivity = null; - f.mFragmentManager = null; + if (!keepActive) { + if (!f.mRetaining) { + makeInactive(f); + } else { + f.mActivity = null; + f.mFragmentManager = null; + } } } } @@ -1007,7 +1010,7 @@ final class FragmentManagerImpl extends FragmentManager { } void moveToState(Fragment f) { - moveToState(f, mCurState, 0, 0); + moveToState(f, mCurState, 0, 0, false); } void moveToState(int newState, boolean always) { @@ -1029,7 +1032,7 @@ final class FragmentManagerImpl extends FragmentManager { for (int i=0; i<mActive.size(); i++) { Fragment f = mActive.get(i); if (f != null) { - moveToState(f, newState, transit, transitStyle); + moveToState(f, newState, transit, transitStyle, false); if (f.mLoaderManager != null) { loadersRunning |= f.mLoaderManager.hasRunningLoaders(); } @@ -1122,7 +1125,7 @@ final class FragmentManagerImpl extends FragmentManager { fragment.mAdded = false; fragment.mRemoving = true; moveToState(fragment, inactive ? Fragment.INITIALIZING : Fragment.CREATED, - transition, transitionStyle); + transition, transitionStyle, false); } } @@ -1189,7 +1192,7 @@ final class FragmentManagerImpl extends FragmentManager { mNeedMenuInvalidate = true; } fragment.mAdded = false; - moveToState(fragment, Fragment.CREATED, transition, transitionStyle); + moveToState(fragment, Fragment.CREATED, transition, transitionStyle, false); } } } @@ -1204,7 +1207,7 @@ final class FragmentManagerImpl extends FragmentManager { if (fragment.mHasMenu && fragment.mMenuVisible) { mNeedMenuInvalidate = true; } - moveToState(fragment, mCurState, transition, transitionStyle); + moveToState(fragment, mCurState, transition, transitionStyle, false); } } } |