From 8c4fa3615dbc09a838f1a341e19c0d0e543f6150 Mon Sep 17 00:00:00 2001 From: George Mount Date: Thu, 2 Feb 2017 07:22:50 -0800 Subject: [PATCH] Fix: fragment destroyed improperly during pop. Bug 34850219 When multiple back stack records were popped together, to the bottom of the stack, the fragment at the bottom would be destroyed. This was caused by the back stack being bumped prior to executing the operations. The back stack record index didn't properly reflect the state it should be in during the operation and the final fragment returned false to isInBackStack(). This CL moves the back stack bumping to immediately prior to executing the operations. Test: I887d565d245cd61434963040c20f887a10bf51dc Change-Id: I3ad2be65cf0e66bf5615c0e912cc233528ee72a3 --- core/java/android/app/FragmentManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 4f68ec71c5ddb..b7c0737487cab 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -2077,8 +2077,6 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate } else { record.trackAddedFragmentsInPop(mTmpAddedFragments); } - final int bumpAmount = isPop ? -1 : 1; - record.bumpBackStackNesting(bumpAmount); addToBackStack = addToBackStack || record.mAddToBackStack; } mTmpAddedFragments.clear(); @@ -2281,8 +2279,10 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate final BackStackRecord record = records.get(i); final boolean isPop = isRecordPop.get(i); if (isPop) { + record.bumpBackStackNesting(-1); record.executePopOps(); } else { + record.bumpBackStackNesting(1); record.executeOps(); } }