Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be6f5042 authored by sergeyv's avatar sergeyv
Browse files

Correctly save retained fragments in the backstack

Test: FragmentLifecycleTest#retainedFragmentsInBackstack
bug:62027280
Change-Id: I4ba20c5138f957107422c46d67095c7c8db2c608
parent 5b49464d
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -2603,23 +2603,25 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
                        f.mTargetIndex = f.mTarget != null ? f.mTarget.mIndex : -1;
                        if (DEBUG) Log.v(TAG, "retainNonConfig: keeping retained " + f);
                    }
                    boolean addedChild = false;
                    FragmentManagerNonConfig child;
                    if (f.mChildFragmentManager != null) {
                        f.mChildFragmentManager.saveNonConfig();
                        FragmentManagerNonConfig child = f.mChildFragmentManager.mSavedNonConfig;
                        if (child != null) {
                            if (childFragments == null) {
                                childFragments = new ArrayList<>();
                        child = f.mChildFragmentManager.mSavedNonConfig;
                    } else {
                        // f.mChildNonConfig may be not null, when the parent fragment is
                        // in the backstack.
                        child = f.mChildNonConfig;
                    }

                    if (childFragments == null && child != null) {
                        childFragments = new ArrayList<>(mActive.size());
                        for (int j = 0; j < i; j++) {
                            childFragments.add(null);
                        }
                    }

                    if (childFragments != null) {
                        childFragments.add(child);
                            addedChild = true;
                        }
                    }
                    if (childFragments != null && !addedChild) {
                        childFragments.add(null);
                    }
                }
            }