“Can not perform this action after onSaveInstanceState” - why am I getting this exception from my activity's onResume method?

后端 未结 7 677
北海茫月
北海茫月 2020-12-08 02:25

My activity invokes the camera with the ACTION_IMAGE_CAPTURE intent. If the camera activity returns succesfully, I set a flag in the onActivityResult callback, and based on

7条回答
  •  佛祖请我去吃肉
    2020-12-08 03:18

    you can use the method commitAllowingStateLoss()

    but be aware you can lose the state of your activity as you can see in google's android reference which explain the different between the two in the following way

    Like commit() but allows the commit to be executed after an activity's state is saved. This is dangerous because the commit can be lost if the activity needs to later be restored from its state, so this should only be used for cases where it is okay for the UI state to change unexpectedly on the user.

    from my experience it may cause the addToBackStack method not to work sometimes so you will need to add it manually on the fragment and of course the state won't be saved (textbox text ext.)

提交回复
热议问题