From 22369d519d41a0b50bffc62b244f52229a907040 Mon Sep 17 00:00:00 2001 From: Eddie Ringle Date: Sun, 29 Jun 2014 16:43:28 -0400 Subject: [PATCH] Fix FragmentTransaction replace() behavior Bug 22174959 According to FragmentTransaction's reference, replace() should be equivalent to remove()'ing every fragment in a given container and then adding the specified fragment to replace those that were removed. Commit ee76efb74b5886f98cdfebfbefe9b69224e016fb broke this intended behavior in the framework. This patch makes it so that the removal loop doesn't end prematurely. It also fixes an issue where the replace operation would remove fragments regardless of their container after encountering the first fragment with a matching container ID. Relevant issues: http://b.android.com/43265 http://b.android.com/52112 http://b.android.com/53393 http://b.android.com/68856 http://b.android.com/70803 Change-Id: Ica4691746ab8979ed974a998e85324e4feacc5e3 Signed-off-by: Eddie Ringle --- core/java/android/app/BackStackRecord.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/BackStackRecord.java b/core/java/android/app/BackStackRecord.java index 903411e345f2d..13030ca285b55 100644 --- a/core/java/android/app/BackStackRecord.java +++ b/core/java/android/app/BackStackRecord.java @@ -717,6 +717,7 @@ final class BackStackRecord extends FragmentTransaction implements break; case OP_REPLACE: { Fragment f = op.fragment; + int containerId = f.mContainerId; if (mManager.mAdded != null) { for (int i = 0; i < mManager.mAdded.size(); i++) { Fragment old = mManager.mAdded.get(i); @@ -724,7 +725,7 @@ final class BackStackRecord extends FragmentTransaction implements Log.v(TAG, "OP_REPLACE: adding=" + f + " old=" + old); } - if (f == null || old.mContainerId == f.mContainerId) { + if (old.mContainerId == containerId) { if (old == f) { op.fragment = f = null; } else {