diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-06-19 15:07:05 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-06-19 15:07:05 -0700 |
commit | acdfbcca6f91bdf3f77ed7b2e699c97ce98c1fb8 (patch) | |
tree | e614239d3d1c647503c3678e50e7c7cfc1c6a0ab /core | |
parent | 0abe556d28f5f5d395559cc6567b05939d1b2640 (diff) | |
download | frameworks_base-acdfbcca6f91bdf3f77ed7b2e699c97ce98c1fb8.zip frameworks_base-acdfbcca6f91bdf3f77ed7b2e699c97ce98c1fb8.tar.gz frameworks_base-acdfbcca6f91bdf3f77ed7b2e699c97ce98c1fb8.tar.bz2 |
Fix issue #6675499: java.lang.RuntimeException: Unable to start...
...activity ComponentInfo{com.google.android.gm/
com.google.android.gm.ui.MailActivityGmail}: java.lang.NullPointerException
There were a number of places in FragmentManagerImpl where we were
not dealing with mAdded being null. In the original implementation,
mAdded would almost always be null if mActive is null. As we have
added features, this has become a less strong guarantee (and it actually
was never completely guaranteed), but there are a lot of places where
we would check for mActive being non-null and assume this meant
mAdded is non-null.
Fix these to correctly check for mAdded.
Bug: 6675499
Change-Id: I2a6a801d8bc89550fc73e12c9c3f8bb0ad6c7fa4
Diffstat (limited to 'core')
-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 9ba5305..39e2423 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 && f.mUserVisibleHint) { @@ -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) { |