diff options
| author | 2017-02-08 10:52:02 -0800 | |
|---|---|---|
| committer | 2017-02-08 11:26:09 -0800 | |
| commit | a42f8e41eebbac6f5a2f0dfa75f95306fcc34588 (patch) | |
| tree | 4a5ec5afe42ddbd5002085757486dd8979de5cff | |
| parent | f9a55d42d2e2adbf5895d04e4790debb145508ed (diff) | |
Delay changing state of added fragments until all executed.
Bug 34963118
When popping multiple transactions, all added fragments
should wait until all transactions are executed before
moving their states to the final state.
This CL brings back the behavior of executing all operations
first before changing the state of added fragments. This means
that intermediate fragments won't be created when popping.
Test: I11da5229bc7104ddc683e1d7d8d929c9db3f5686
Change-Id: I472860cfe94a33db42e9a1d3727213ab5d5075e7
| -rw-r--r-- | core/java/android/app/BackStackRecord.java | 7 | ||||
| -rw-r--r-- | core/java/android/app/FragmentManager.java | 7 |
2 files changed, 10 insertions, 4 deletions
diff --git a/core/java/android/app/BackStackRecord.java b/core/java/android/app/BackStackRecord.java index 66b2355dcb6e..c88448aa2ee7 100644 --- a/core/java/android/app/BackStackRecord.java +++ b/core/java/android/app/BackStackRecord.java @@ -813,8 +813,11 @@ final class BackStackRecord extends FragmentTransaction implements /** * Reverses the execution of the operations within this transaction. The Fragment states will * only be modified if optimizations are not allowed. + * + * @param moveToState {@code true} if added fragments should be moved to their final state + * in unoptimized transactions */ - void executePopOps() { + void executePopOps(boolean moveToState) { for (int opNum = mOps.size() - 1; opNum >= 0; opNum--) { final Op op = mOps.get(opNum); Fragment f = op.fragment; @@ -860,7 +863,7 @@ final class BackStackRecord extends FragmentTransaction implements mManager.moveFragmentToExpectedState(f); } } - if (!mAllowOptimization) { + if (!mAllowOptimization && moveToState) { mManager.moveToState(mManager.mCurState, true); } } diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index b7c0737487ca..d32cf3c4b54a 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -2170,7 +2170,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate if (isPop) { record.executeOps(); } else { - record.executePopOps(); + record.executePopOps(false); } // move to the end @@ -2280,7 +2280,10 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate final boolean isPop = isRecordPop.get(i); if (isPop) { record.bumpBackStackNesting(-1); - record.executePopOps(); + // Only execute the add operations at the end of + // all transactions. + boolean moveToState = i == (endIndex - 1); + record.executePopOps(moveToState); } else { record.bumpBackStackNesting(1); record.executeOps(); |