summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author George Mount <mount@google.com> 2017-03-29 14:56:05 -0700
committer George Mount <mount@google.com> 2017-03-29 15:17:44 -0700
commit5dd7c9af6d99f1a655cb9f4fd301b2de31322aef (patch)
tree042705191531fc89e836997908f1d61be59e020a
parentc7146beabe21c84248c2c62336b0af8c2f19f4f5 (diff)
Fix getting wrong instance when restoring non-config
Bug 36679897 When restoring the non-config fragments, the wrong index was being used to lookup the fragment fromt the list of active fragment states. Test: Ic862fd9670408dab09ab5817cdec21e91aef001b Change-Id: Ic5a8e723041949e6d01d4f5ddc6d54e491143b59
-rw-r--r--core/java/android/app/FragmentManager.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 5d025d96759a..0c1be07ab231 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -2725,7 +2725,15 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
for (int i = 0; i < count; i++) {
Fragment f = nonConfigFragments.get(i);
if (DEBUG) Log.v(TAG, "restoreAllState: re-attaching retained " + f);
- FragmentState fs = fms.mActive[f.mIndex];
+ int index = 0; // index of f in fms.mActive
+ while (index < fms.mActive.length && fms.mActive[index].mIndex != f.mIndex) {
+ index++;
+ }
+ if (index == fms.mActive.length) {
+ throwException(new IllegalStateException("Could not find active fragment "
+ + "with index " + f.mIndex));
+ }
+ FragmentState fs = fms.mActive[index];
fs.mInstance = f;
f.mSavedViewState = null;
f.mBackStackNesting = 0;