diff options
Diffstat (limited to 'core/java/android/app/FragmentManager.java')
-rw-r--r-- | core/java/android/app/FragmentManager.java | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index d8777fb..b0cc37b 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -1118,7 +1118,9 @@ final class FragmentManagerImpl extends FragmentManager { if (DEBUG) Log.v(TAG, "remove: " + fragment + " nesting=" + fragment.mBackStackNesting); final boolean inactive = !fragment.isInBackStack(); if (!fragment.mDetached || inactive) { - mAdded.remove(fragment); + if (mAdded != null) { + mAdded.remove(fragment); + } if (fragment.mHasMenu && fragment.mMenuVisible) { mNeedMenuInvalidate = true; } @@ -1187,7 +1189,9 @@ final class FragmentManagerImpl extends FragmentManager { fragment.mDetached = true; if (fragment.mAdded) { // We are not already in back stack, so need to remove the fragment. - mAdded.remove(fragment); + if (mAdded != null) { + mAdded.remove(fragment); + } if (fragment.mHasMenu && fragment.mMenuVisible) { mNeedMenuInvalidate = true; } @@ -1202,6 +1206,9 @@ final class FragmentManagerImpl extends FragmentManager { if (fragment.mDetached) { fragment.mDetached = false; if (!fragment.mAdded) { + if (mAdded == null) { + mAdded = new ArrayList<Fragment>(); + } mAdded.add(fragment); fragment.mAdded = true; if (fragment.mHasMenu && fragment.mMenuVisible) { @@ -1213,7 +1220,7 @@ final class FragmentManagerImpl extends FragmentManager { } public Fragment findFragmentById(int id) { - if (mActive != null) { + if (mAdded != null) { // First look through added fragments. for (int i=mAdded.size()-1; i>=0; i--) { Fragment f = mAdded.get(i); @@ -1221,6 +1228,8 @@ final class FragmentManagerImpl extends FragmentManager { return f; } } + } + if (mActive != null) { // Now for any known fragment. for (int i=mActive.size()-1; i>=0; i--) { Fragment f = mActive.get(i); @@ -1233,7 +1242,7 @@ final class FragmentManagerImpl extends FragmentManager { } public Fragment findFragmentByTag(String tag) { - if (mActive != null && tag != null) { + if (mAdded != null && tag != null) { // First look through added fragments. for (int i=mAdded.size()-1; i>=0; i--) { Fragment f = mAdded.get(i); @@ -1241,6 +1250,8 @@ final class FragmentManagerImpl extends FragmentManager { return f; } } + } + if (mActive != null && tag != null) { // Now for any known fragment. for (int i=mActive.size()-1; i>=0; i--) { Fragment f = mActive.get(i); @@ -1817,7 +1828,7 @@ final class FragmentManagerImpl extends FragmentManager { } public void dispatchConfigurationChanged(Configuration newConfig) { - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null) { @@ -1828,7 +1839,7 @@ final class FragmentManagerImpl extends FragmentManager { } public void dispatchLowMemory() { - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null) { @@ -1839,7 +1850,7 @@ final class FragmentManagerImpl extends FragmentManager { } public void dispatchTrimMemory(int level) { - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null) { @@ -1852,7 +1863,7 @@ final class FragmentManagerImpl extends FragmentManager { public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater) { boolean show = false; ArrayList<Fragment> newMenus = null; - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { @@ -1882,7 +1893,7 @@ final class FragmentManagerImpl extends FragmentManager { public boolean dispatchPrepareOptionsMenu(Menu menu) { boolean show = false; - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { @@ -1895,7 +1906,7 @@ final class FragmentManagerImpl extends FragmentManager { } public boolean dispatchOptionsItemSelected(MenuItem item) { - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { @@ -1909,7 +1920,7 @@ final class FragmentManagerImpl extends FragmentManager { } public boolean dispatchContextItemSelected(MenuItem item) { - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null && !f.mHidden) { @@ -1923,7 +1934,7 @@ final class FragmentManagerImpl extends FragmentManager { } public void dispatchOptionsMenuClosed(Menu menu) { - if (mActive != null) { + if (mAdded != null) { for (int i=0; i<mAdded.size(); i++) { Fragment f = mAdded.get(i); if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) { |