}
}
- void moveToState(int newState) {
+ /**
+ * Changes the state of the fragment manager to {@code newState}. If the fragment manager
+ * changes state or {@code always} is {@code true}, any fragments within it have their
+ * states updated as well.
+ *
+ * @param newState The new state for the fragment manager
+ * @param always If {@code true}, all fragments update their state, even
+ * if {@code newState} matches the current fragment manager's state.
+ */
+ void moveToState(int newState, boolean always) {
if (mHost == null && newState != Fragment.INITIALIZING) {
throw new IllegalStateException("No activity");
}
+ if (!always && mCurState == newState) {
+ return;
+ }
+
mCurState = newState;
if (mActive != null) {
// need to run something now
FragmentTransition.startTransitions(this, records, isRecordPop, startIndex,
postponeIndex, true);
- moveToState(mCurState);
+ moveToState(mCurState, true);
}
for (int recordNum = startIndex; recordNum < endIndex; recordNum++) {
FragmentTransition.startTransitions(this, records, isRecordPop, 0, 1, true);
}
if (moveToState) {
- moveToState(mCurState);
+ moveToState(mCurState, true);
} else if (mActive != null) {
final int numActive = mActive.size();
for (int i = 0; i < numActive; i++) {
public void dispatchCreate() {
mStateSaved = false;
- moveToState(Fragment.CREATED);
+ moveToState(Fragment.CREATED, false);
}
public void dispatchActivityCreated() {
mStateSaved = false;
- moveToState(Fragment.ACTIVITY_CREATED);
+ moveToState(Fragment.ACTIVITY_CREATED, false);
}
public void dispatchStart() {
mStateSaved = false;
- moveToState(Fragment.STARTED);
+ moveToState(Fragment.STARTED, false);
}
public void dispatchResume() {
mStateSaved = false;
- moveToState(Fragment.RESUMED);
+ moveToState(Fragment.RESUMED, false);
}
public void dispatchPause() {
- moveToState(Fragment.STARTED);
+ moveToState(Fragment.STARTED, false);
}
public void dispatchStop() {
- moveToState(Fragment.STOPPED);
+ moveToState(Fragment.STOPPED, false);
}
public void dispatchDestroyView() {
- moveToState(Fragment.CREATED);
+ moveToState(Fragment.CREATED, false);
}
public void dispatchDestroy() {
mDestroyed = true;
execPendingActions();
- moveToState(Fragment.INITIALIZING);
+ moveToState(Fragment.INITIALIZING, false);
mHost = null;
mContainer = null;
mParent = null;