diff options
| author | Dianne Hackborn <hackbod@google.com> | 2011-06-10 17:03:42 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2011-06-10 18:34:54 -0700 |
| commit | afc4b283fdaedec9bf32492a019b43cc33edc9b6 (patch) | |
| tree | 6fde7ed8d76aa76bd93eebc427d4ceb0282d71ea /core/java/android/app/Fragment.java | |
| parent | 2bb2d48f9ca1726b8de957ec7ea321c767409c12 (diff) | |
Fix some problems with moving in and out of detached state.
Loaders were not being re-initialized correctly when coming back
(this would also impact the back stack). The ListView also wasn't
working correctly, and there were also problems with simply
re-using a Fragment instance after it had been removed.
Change-Id: I534b091ae09c0ef7ffffe9d68049e6840e8926b3
Diffstat (limited to 'core/java/android/app/Fragment.java')
| -rw-r--r-- | core/java/android/app/Fragment.java | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java index 14ffd3be78ca..f2be9ad9ba3f 100644 --- a/core/java/android/app/Fragment.java +++ b/core/java/android/app/Fragment.java @@ -587,11 +587,6 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener mWho = "android:fragment:" + mIndex; } - final void clearIndex() { - mIndex = -1; - mWho = null; - } - final boolean isInBackStack() { return mBackStackNesting > 0; } @@ -783,6 +778,15 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener } /** + * Return true if the fragment has been explicitly detached from the UI. + * That is, {@link FragmentTransaction#detach(Fragment) + * FragmentTransaction.detach(Fragment)} has been used on it. + */ + final public boolean isDetached() { + return mDetached; + } + + /** * Return true if this fragment is currently being removed from its * activity. This is <em>not</em> whether its activity is finishing, but * rather whether it is in the process of being removed from its activity. @@ -1203,6 +1207,35 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener } /** + * Called by the fragment manager once this fragment has been removed, + * so that we don't have any left-over state if the application decides + * to re-use the instance. This only clears state that the framework + * internally manages, not things the application sets. + */ + void initState() { + mIndex = -1; + mWho = null; + mAdded = false; + mRemoving = false; + mResumed = false; + mFromLayout = false; + mInLayout = false; + mRestored = false; + mBackStackNesting = 0; + mFragmentManager = null; + mActivity = mImmediateActivity = null; + mFragmentId = 0; + mContainerId = 0; + mTag = null; + mHidden = false; + mDetached = false; + mRetaining = false; + mLoaderManager = null; + mLoadersStarted = false; + mCheckedForLoaderManager = false; + } + + /** * Called when the fragment is no longer attached to its activity. This * is called after {@link #onDestroy()}. */ @@ -1429,6 +1462,13 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener } } + void performStart() { + onStart(); + if (mLoaderManager != null) { + mLoaderManager.doReportStart(); + } + } + void performStop() { onStop(); @@ -1447,4 +1487,11 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener } } } + + void performDestroyView() { + onDestroyView(); + if (mLoaderManager != null) { + mLoaderManager.doReportNextStart(); + } + } } |
