A practical library for committing Fragment Transactions safely.
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2080)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2106)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:683)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:637)
Also check : Fragment Transactions & Activity State Loss
- Bind the TransactionKeeper in your main UI (Activity / Fragment)
transactionKeeper = TransactionKeeper(this)
- Wrap your asynchronous Fragment transaction logic as below :
transactionKeeper.execute { activity ->
kotlin.run {
// commit your own Framgment transaction here
}
}
For detail info, please check the MainActivity
in the app
module.
kshilovskiy's action-buffer provides an example of avoiding the IllegalStateException during the fragment transition while dealing with background tasks.
- Refactor the library code to provide more convenient APIs