Monday, June 2, 2014

Bug - AOSP Gallery crash - commit after onSaveInstanceState

Call Stack
05-27 12:18:24.948  2471  2471 E AndroidRuntime: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1361)
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
05-27 12:18:24.948  2471  2471 E AndroidRuntime:  at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)

Root cause:
onSaveInstanceState happen before the commit. The commit caused by orientation changed and the save state caused by another dialog choose from menu force the activity call the sate to save pending changes.

Solution:
1. use commitAllowLose
2. android:configChanges="orientation" in AndroidManifest.xml
3. override the onCreate as below 
public void onCreate() {
    super.onCreate();
    // TODO Put your application initialization code here.
  }


No comments:

Post a Comment