summaryrefslogtreecommitdiffstats
path: root/core/java/android/app/FragmentManager.java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2011-08-29 16:53:49 -0700
committerDianne Hackborn <hackbod@google.com>2011-08-29 17:58:17 -0700
commit6c285977a0dc9605348bd9530282c7d006cbf8bd (patch)
tree51e82d31ba70c5d33b573a99e6ad09cca03e01dd /core/java/android/app/FragmentManager.java
parentb5d80fca2eb7f6053e6d404a0d4a7c213dad1317 (diff)
downloadframeworks_base-6c285977a0dc9605348bd9530282c7d006cbf8bd.zip
frameworks_base-6c285977a0dc9605348bd9530282c7d006cbf8bd.tar.gz
frameworks_base-6c285977a0dc9605348bd9530282c7d006cbf8bd.tar.bz2
Fix issues 5158104 and 4981556 (fragment problems)
5158104: com.android.contacts: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1201) The ViewPager can just commit without worrying about a state loss, since it can correctly reconstruct its state later. 4981556: Fragment.mImmediateActivity doesn't get restored on orientation change I am giving up on this thing; I just don't see how it can actually be correct. So now instead of getting an exception about a dup add/remove at point of the add/remove call, this will happen later when processing the transaction. Also add an API for controlling the visibility of menus, which ViewPager can use to have the correct menus shows. And add a method to get the name of a back stack entry. Change-Id: Idcba14cfa2a172545a7a2a2c466cb49ceb789619
Diffstat (limited to 'core/java/android/app/FragmentManager.java')
-rw-r--r--core/java/android/app/FragmentManager.java29
1 files changed, 17 insertions, 12 deletions
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 70e6866..7a6759f 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -67,6 +67,13 @@ public abstract class FragmentManager {
public int getId();
/**
+ * Get the name that was supplied to
+ * {@link FragmentTransaction#addToBackStack(String)
+ * FragmentTransaction.addToBackStack(String)} when creating this entry.
+ */
+ public String getName();
+
+ /**
* Return the full bread crumb title resource identifier for the entry,
* or 0 if it does not have one.
*/
@@ -949,7 +956,6 @@ final class FragmentManagerImpl extends FragmentManager {
if (!f.mRetaining) {
makeInactive(f);
} else {
- f.mImmediateActivity = null;
f.mActivity = null;
f.mFragmentManager = null;
}
@@ -1037,7 +1043,7 @@ final class FragmentManagerImpl extends FragmentManager {
mAdded.add(fragment);
fragment.mAdded = true;
fragment.mRemoving = false;
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
if (moveToStateNow) {
@@ -1051,7 +1057,7 @@ final class FragmentManagerImpl extends FragmentManager {
final boolean inactive = !fragment.isInBackStack();
if (!fragment.mDetached || inactive) {
mAdded.remove(fragment);
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.mAdded = false;
@@ -1086,7 +1092,7 @@ final class FragmentManagerImpl extends FragmentManager {
fragment.mView.setVisibility(View.GONE);
}
}
- if (fragment.mAdded && fragment.mHasMenu) {
+ if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.onHiddenChanged(true);
@@ -1106,7 +1112,7 @@ final class FragmentManagerImpl extends FragmentManager {
}
fragment.mView.setVisibility(View.VISIBLE);
}
- if (fragment.mAdded && fragment.mHasMenu) {
+ if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.onHiddenChanged(false);
@@ -1120,7 +1126,7 @@ final class FragmentManagerImpl extends FragmentManager {
if (fragment.mAdded) {
// We are not already in back stack, so need to remove the fragment.
mAdded.remove(fragment);
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.mAdded = false;
@@ -1136,7 +1142,7 @@ final class FragmentManagerImpl extends FragmentManager {
if (!fragment.mAdded) {
mAdded.add(fragment);
fragment.mAdded = true;
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
moveToState(fragment, mCurState, transition, transitionStyle);
@@ -1640,7 +1646,6 @@ final class FragmentManagerImpl extends FragmentManager {
"No instantiated fragment for index #" + fms.mAdded[i]);
}
f.mAdded = true;
- f.mImmediateActivity = mActivity;
if (DEBUG) Log.v(TAG, "restoreAllState: making added #" + i + ": " + f);
mAdded.add(f);
}
@@ -1748,7 +1753,7 @@ final class FragmentManagerImpl extends FragmentManager {
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
show = true;
f.onCreateOptionsMenu(menu, inflater);
if (newMenus == null) {
@@ -1778,7 +1783,7 @@ final class FragmentManagerImpl extends FragmentManager {
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
show = true;
f.onPrepareOptionsMenu(menu);
}
@@ -1791,7 +1796,7 @@ final class FragmentManagerImpl extends FragmentManager {
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
if (f.onOptionsItemSelected(item)) {
return true;
}
@@ -1819,7 +1824,7 @@ final class FragmentManagerImpl extends FragmentManager {
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
f.onOptionsMenuClosed(menu);
}
}