FragmentManager is already executing transactions. When is it safe to initialise pager after commit? : <p>I have an activity hosting two fragments. The activity starts off showing a loader while it loads an object. The loaded object is then passed to both fragments as arguments via newInstance methods and those fragments are attached.</p>

<pre><code>final FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.replace(R.id.container1, Fragment1.newInstance(loadedObject));
trans.replace(R.id.container2, Fragment2.newInstance(loadedObject));
trans.commit();
</code></pre>

<p>The second fragment contains a android.support.v4.view.ViewPager and tabs. onResume we initialise it like follows</p>

<pre><code>viewPager.setAdapter(adapter);
viewPager.setOffscreenPageLimit(adapter.getCount()); //the count is always &lt; 4
tabLayout.setupWithViewPager(viewPager);
</code></pre>

<p>The problem is android then throws </p>

<blockquote>
  <p>java.lang.IllegalStateException: FragmentManager is already executing
  transactions</p>
</blockquote>

<p>With this stack trace: <em>(I took <code>android.support</code> out of the package names just for brevity)</em></p>

<blockquote>
  <p>v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1620)
                                                                                         at
  v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:637)
                                                                                         at
  v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
                                                                                         at v4.view.ViewPager.populate(ViewPager.java:1235)
                                                                                         at v4.view.ViewPager.populate(ViewPager.java:1083)
                                                                                         at
  v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:847)</p>
</blockquote>

<p>The data shows if <code>setOffscreenPageLimit(...);</code> is removed. Is there another way to avoid this issue?</p>

<p>When in the lifecycle is the fragment transaction complete so that I can wait to setup my pager?</p>
