I'm showing an empty fragment if the user has no data. In that emptyFragment (in onViewCreated
) I check for a condition and sometimes would like to replace that empty Fragment with another one, so I call a method on the according activity which replaced the fragment.
Some users (currently only Samsung, 6.0.1 but I don't know if that means anything) experience a crash on the line where I executePendingTransactions
:
IllegalStateException:
Fatal Exception: java.lang.RuntimeException
Unable to resume activity
{....app.activities.MyActivity_}:
java.lang.IllegalStateException: FragmentManager is already executing transactions
Is this a bug in 6.0.1 or is onViewCreated
the wrong place to do this?
EDIT
Would this be a possible solution?
if (addToBackStack) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, contentFragment, name).addToBackStack(name).commitAllowingStateLoss();
getSupportFragmentManager().executePendingTransactions();
} else {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, contentFragment, name).commitNow();
}