I have FragmentActivity, which contains the layout and layout-land. After changing orientation of the device and then commit() fragment I get an error that I can not fix:
IllegalStateException: Can not perform this action after onSaveInstanceState
I can not lock change screen orientation , as I need to change the layout to layout-land. How do I fix this problem? Thanks!
Inside the onCreate
method of your Fragment (not your FragmentActivity) call Fragment.setOnRetainInstance(true)
.
You call commit()
only once inside the overrided onCreate method of your FragmentActivity. No need to call it again after changing the orientation. If what you want is saving the Fragment's state after rotation, then Fragment.setOnRetainInstance(true)
is the guy you are looking for.