diff options
| author | 2016-01-12 18:30:47 +0000 | |
|---|---|---|
| committer | 2016-01-12 18:30:47 +0000 | |
| commit | 0c57596905977e7243a9e4bae9dbf7a18742ec54 (patch) | |
| tree | 97be660856ed68a00e121915f5f798b684148b95 | |
| parent | 9ec29e3d6dce8a0dca6e93c1ba615f4732e0afb0 (diff) | |
| parent | d1d4d9cb3a2f40aa1a476b9e55c7a4981da21c0f (diff) | |
Merge "Eagerly update fragment state when moving between states"
| -rw-r--r-- | core/java/android/app/Fragment.java | 15 | ||||
| -rw-r--r-- | core/java/android/app/FragmentManager.java | 10 |
2 files changed, 16 insertions, 9 deletions
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java index a73ad09d5f55..e163b1c2ad23 100644 --- a/core/java/android/app/Fragment.java +++ b/core/java/android/app/Fragment.java @@ -409,9 +409,6 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene // If set this fragment is being removed from its activity. boolean mRemoving; - // True if the fragment is in the resumed state. - boolean mResumed; - // Set to true if this fragment was instantiated from a layout file. boolean mFromLayout; @@ -928,7 +925,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene * for the duration of {@link #onResume()} and {@link #onPause()} as well. */ final public boolean isResumed() { - return mResumed; + return mState >= RESUMED; } /** @@ -1630,7 +1627,6 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene mWho = null; mAdded = false; mRemoving = false; - mResumed = false; mFromLayout = false; mInLayout = false; mRestored = false; @@ -2113,7 +2109,6 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); writer.print(" mRemoving="); writer.print(mRemoving); - writer.print(" mResumed="); writer.print(mResumed); writer.print(" mFromLayout="); writer.print(mFromLayout); writer.print(" mInLayout="); writer.println(mInLayout); writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); @@ -2208,6 +2203,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene if (mChildFragmentManager != null) { mChildFragmentManager.noteStateNotSaved(); } + mState = CREATED; mCalled = false; onCreate(savedInstanceState); if (!mCalled) { @@ -2238,6 +2234,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene if (mChildFragmentManager != null) { mChildFragmentManager.noteStateNotSaved(); } + mState = ACTIVITY_CREATED; mCalled = false; onActivityCreated(savedInstanceState); if (!mCalled) { @@ -2254,6 +2251,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene mChildFragmentManager.noteStateNotSaved(); mChildFragmentManager.execPendingActions(); } + mState = STARTED; mCalled = false; onStart(); if (!mCalled) { @@ -2273,6 +2271,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene mChildFragmentManager.noteStateNotSaved(); mChildFragmentManager.execPendingActions(); } + mState = RESUMED; mCalled = false; onResume(); if (!mCalled) { @@ -2389,6 +2388,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene if (mChildFragmentManager != null) { mChildFragmentManager.dispatchPause(); } + mState = STARTED; mCalled = false; onPause(); if (!mCalled) { @@ -2401,6 +2401,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene if (mChildFragmentManager != null) { mChildFragmentManager.dispatchStop(); } + mState = STOPPED; mCalled = false; onStop(); if (!mCalled) { @@ -2428,6 +2429,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene if (mChildFragmentManager != null) { mChildFragmentManager.dispatchDestroyView(); } + mState = CREATED; mCalled = false; onDestroyView(); if (!mCalled) { @@ -2443,6 +2445,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene if (mChildFragmentManager != null) { mChildFragmentManager.dispatchDestroy(); } + mState = INITIALIZING; mCalled = false; onDestroy(); if (!mCalled) { diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 696ccdb207c1..84ae09d7e988 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -1004,7 +1004,6 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate case Fragment.STARTED: if (newState > Fragment.STARTED) { if (DEBUG) Log.v(TAG, "moveto RESUMED: " + f); - f.mResumed = true; f.performResume(); // Get rid of this in case we saved it and never needed it. f.mSavedFragmentState = null; @@ -1017,7 +1016,6 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate if (newState < Fragment.RESUMED) { if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f); f.performPause(); - f.mResumed = false; } case Fragment.STARTED: if (newState < Fragment.STARTED) { @@ -1096,6 +1094,8 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f); if (!f.mRetaining) { f.performDestroy(); + } else { + f.mState = Fragment.INITIALIZING; } f.mCalled = false; @@ -1119,7 +1119,11 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate } } - f.mState = newState; + if (f.mState != newState) { + Log.w(TAG, "moveToState: Fragment state for " + f + " not updated inline; " + + "expected state " + newState + " found " + f.mState); + f.mState = newState; + } } void moveToState(Fragment f) { |