voidrestoreSaveState(@Nullable Parcelable state) { // If there is no saved state at all, then there's nothing else to do if (state == null) return; FragmentManagerStatefms= (FragmentManagerState) state; if (fms.mActive == null) return;
// Build the full list of active fragments, instantiating them from // their saved state. mFragmentStore.resetActiveFragments(); for (FragmentState fs : fms.mActive) { if (fs != null) { FragmentStateManager fragmentStateManager; FragmentretainedFragment= mNonConfig.findRetainedFragmentByWho(fs.mWho); if (retainedFragment != null) { if (isLoggingEnabled(Log.VERBOSE)) { Log.v(TAG, "restoreSaveState: re-attaching retained " + retainedFragment); } // fragmentStateManager = newFragmentStateManager(mLifecycleCallbacksDispatcher, retainedFragment, fs); } else { // 在这重新创建了Fragment fragmentStateManager = newFragmentStateManager(mLifecycleCallbacksDispatcher, mHost.getContext().getClassLoader(), getFragmentFactory(), fs); } Fragmentf= fragmentStateManager.getFragment(); f.mFragmentManager = this; if (isLoggingEnabled(Log.VERBOSE)) { Log.v(TAG, "restoreSaveState: active (" + f.mWho + "): " + f); } fragmentStateManager.restoreState(mHost.getContext().getClassLoader()); mFragmentStore.makeActive(fragmentStateManager); // Catch the FragmentStateManager up to our current state // In almost all cases, this is Fragment.INITIALIZING, but just in // case a FragmentController does something...unique, let's do this anyways. fragmentStateManager.setFragmentManagerState(mCurState); } }