onViewCreated - wrong place to replace fragment?
<p>I'm showing an empty fragment if the user has no data. In that emptyFragment (in <code>onViewCreated</code>) 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.</p>

<p>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 <code>executePendingTransactions</code>:</p>

<pre><code>IllegalStateException:

Fatal Exception: java.lang.RuntimeException
Unable to resume activity
{....app.activities.MyActivity_}:
java.lang.IllegalStateException: FragmentManager is already executing transactions
</code></pre>

<p>Is this a bug in 6.0.1 or is <code>onViewCreated</code> the wrong place to do this?</p>

<p><strong>EDIT</strong></p>

<p>Would this be a possible solution?</p>

<pre><code>    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();
    }
</code></pre>