Merge "Fix Fragment.onCreate() not being called in some cases."
This commit is contained in:
committed by
Android (Google) Code Review
commit
d2eb1035ef
@@ -42,7 +42,6 @@ import android.util.AndroidRuntimeException;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DebugUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SuperNotCalledException;
|
||||
import android.view.ContextMenu;
|
||||
@@ -406,6 +405,11 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
||||
// getLayoutInflater()
|
||||
LayoutInflater mLayoutInflater;
|
||||
|
||||
// Keep track of whether or not this Fragment has run performCreate(). Retained instance
|
||||
// fragments can have mRetaining set to true without going through creation, so we must
|
||||
// track it separately.
|
||||
boolean mIsCreated;
|
||||
|
||||
/**
|
||||
* State information that has been retrieved from a fragment instance
|
||||
* through {@link FragmentManager#saveFragmentInstanceState(Fragment)
|
||||
@@ -2483,6 +2487,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
||||
mState = CREATED;
|
||||
mCalled = false;
|
||||
onCreate(savedInstanceState);
|
||||
mIsCreated = true;
|
||||
if (!mCalled) {
|
||||
throw new SuperNotCalledException("Fragment " + this
|
||||
+ " did not call through to super.onCreate()");
|
||||
@@ -2759,6 +2764,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
||||
}
|
||||
mState = INITIALIZING;
|
||||
mCalled = false;
|
||||
mIsCreated = false;
|
||||
onDestroy();
|
||||
if (!mCalled) {
|
||||
throw new SuperNotCalledException("Fragment " + this
|
||||
|
||||
@@ -1232,7 +1232,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
|
||||
}
|
||||
dispatchOnFragmentAttached(f, mHost.getContext(), false);
|
||||
|
||||
if (!f.mRetaining) {
|
||||
if (!f.mIsCreated) {
|
||||
dispatchOnFragmentPreCreated(f, f.mSavedFragmentState, false);
|
||||
f.performCreate(f.mSavedFragmentState);
|
||||
dispatchOnFragmentCreated(f, f.mSavedFragmentState, false);
|
||||
|
||||
Reference in New Issue
Block a user