I have a guess as to what this could be, especially if it is hard to reproduce. You issue is that you are doing a FragmentTransaction
after an asynchronous callback, during which any number of things can happen. Therefore you cannot guarantee where you will be in the Activity Lifecycle. The problem is Fragments and State Loss.
http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html
https://stackoverflow.com/a/17527246/1856960
Say for example, the user starts the AsyncTask, then ends the Activity, starts another one, or hits the home button. All of this will put the Activity in the background and may trigger a call to onSaveInstanceState
. You cannot commit a Fragment Transaction after onSaveInstanceState is called. This is because the FragmentManager
and all the state associated with it has already been bundled in onSaveInstanceState
, so if the Activity is destroyed and re-created, you will lose your Fragment Transaction.
As for fixing the issue, I wish I had a good suggestion for you. You can look into FragmentTransaction#commitAllowingStateLoss
but this should only be used if you are sure the potential downfalls will not negatively impact your application. See the links above for more information.