Merge "Fix bugs around restoring nested retained instance fragments" into nyc-dev
am: 30ac43e
* commit '30ac43e4acc4ed5673ea40d6643e36fadec5411c':
Fix bugs around restoring nested retained instance fragments
This commit is contained in:
@@ -1429,16 +1429,20 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
|||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final int version = context != null ? context.getApplicationInfo().targetSdkVersion : 0;
|
final int version = context != null ? context.getApplicationInfo().targetSdkVersion : 0;
|
||||||
if (version >= Build.VERSION_CODES.N) {
|
if (version >= Build.VERSION_CODES.N) {
|
||||||
if (savedInstanceState != null) {
|
restoreChildFragmentState(savedInstanceState, true);
|
||||||
Parcelable p = savedInstanceState.getParcelable(Activity.FRAGMENTS_TAG);
|
}
|
||||||
if (p != null) {
|
}
|
||||||
if (mChildFragmentManager == null) {
|
|
||||||
instantiateChildFragmentManager();
|
void restoreChildFragmentState(@Nullable Bundle savedInstanceState, boolean provideNonConfig) {
|
||||||
}
|
if (savedInstanceState != null) {
|
||||||
mChildFragmentManager.restoreAllState(p, mChildNonConfig);
|
Parcelable p = savedInstanceState.getParcelable(Activity.FRAGMENTS_TAG);
|
||||||
mChildNonConfig = null;
|
if (p != null) {
|
||||||
mChildFragmentManager.dispatchCreate();
|
if (mChildFragmentManager == null) {
|
||||||
|
instantiateChildFragmentManager();
|
||||||
}
|
}
|
||||||
|
mChildFragmentManager.restoreAllState(p, provideNonConfig ? mChildNonConfig : null);
|
||||||
|
mChildNonConfig = null;
|
||||||
|
mChildFragmentManager.dispatchCreate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1692,6 +1696,18 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
|||||||
*/
|
*/
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
mCalled = true;
|
mCalled = true;
|
||||||
|
|
||||||
|
// Destroy the child FragmentManager if we still have it here.
|
||||||
|
// We won't unless we're retaining our instance and if we do,
|
||||||
|
// our child FragmentManager instance state will have already been saved.
|
||||||
|
if (mChildFragmentManager != null) {
|
||||||
|
if (!mRetaining) {
|
||||||
|
throw new IllegalStateException("Child FragmentManager of " + this + " was not "
|
||||||
|
+ " destroyed and this fragment is not retaining instance");
|
||||||
|
}
|
||||||
|
mChildFragmentManager.dispatchDestroy();
|
||||||
|
mChildFragmentManager = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2252,16 +2268,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
|||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final int version = context != null ? context.getApplicationInfo().targetSdkVersion : 0;
|
final int version = context != null ? context.getApplicationInfo().targetSdkVersion : 0;
|
||||||
if (version < Build.VERSION_CODES.N) {
|
if (version < Build.VERSION_CODES.N) {
|
||||||
if (savedInstanceState != null) {
|
restoreChildFragmentState(savedInstanceState, false);
|
||||||
Parcelable p = savedInstanceState.getParcelable(Activity.FRAGMENTS_TAG);
|
|
||||||
if (p != null) {
|
|
||||||
if (mChildFragmentManager == null) {
|
|
||||||
instantiateChildFragmentManager();
|
|
||||||
}
|
|
||||||
mChildFragmentManager.restoreAllState(p, null);
|
|
||||||
mChildFragmentManager.dispatchCreate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -941,6 +941,9 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
|
|||||||
|
|
||||||
if (!f.mRetaining) {
|
if (!f.mRetaining) {
|
||||||
f.performCreate(f.mSavedFragmentState);
|
f.performCreate(f.mSavedFragmentState);
|
||||||
|
} else {
|
||||||
|
f.restoreChildFragmentState(f.mSavedFragmentState, true);
|
||||||
|
f.mState = Fragment.CREATED;
|
||||||
}
|
}
|
||||||
f.mRetaining = false;
|
f.mRetaining = false;
|
||||||
if (f.mFromLayout) {
|
if (f.mFromLayout) {
|
||||||
@@ -1009,6 +1012,9 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
|
|||||||
f.mSavedFragmentState = null;
|
f.mSavedFragmentState = null;
|
||||||
}
|
}
|
||||||
case Fragment.ACTIVITY_CREATED:
|
case Fragment.ACTIVITY_CREATED:
|
||||||
|
if (newState > Fragment.ACTIVITY_CREATED) {
|
||||||
|
f.mState = Fragment.STOPPED;
|
||||||
|
}
|
||||||
case Fragment.STOPPED:
|
case Fragment.STOPPED:
|
||||||
if (newState > Fragment.STOPPED) {
|
if (newState > Fragment.STOPPED) {
|
||||||
if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
|
if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
|
||||||
@@ -1108,7 +1114,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
|
|||||||
if (!f.mRetaining) {
|
if (!f.mRetaining) {
|
||||||
f.performDestroy();
|
f.performDestroy();
|
||||||
} else {
|
} else {
|
||||||
f.mState = Fragment.INITIALIZING;
|
f.mState = Fragment.CREATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
f.mCalled = false;
|
f.mCalled = false;
|
||||||
@@ -1124,7 +1130,6 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
|
|||||||
f.mHost = null;
|
f.mHost = null;
|
||||||
f.mParentFragment = null;
|
f.mParentFragment = null;
|
||||||
f.mFragmentManager = null;
|
f.mFragmentManager = null;
|
||||||
f.mChildFragmentManager = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user