title: IllegalStateException Fragment Manager Already In Use
body: <p>I have been implementing Navigation drawer and tabs within some fragments of navigation drawer for a long time now. The issue never came up and it still does not appears in few fragments but it appears in only two of the fragments in navigation drawer.</p>
  
  <p>In navigation drawer each item represents a fragment which are opened by following code</p>
  
  <pre><code>FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
  currentFragment = new SomeFragment();
  home_container_drawer_layout.closeDrawers();
  fragmentTransaction = setFTAnimation(fragmentTransaction);
  fragmentTransaction.replace(R.id.framelayout_activity_home, currentFragment).commitNow();
  </code></pre>
  
  <p>As soon as the fragment is loaded I make a service call using ION wrapper that I created and on response I set up tabs dynamically in a ViewPager in that fragment</p>
  
  <p>Following are two functions for setting tab listener and setting viewpager adapter</p>
  
  <pre><code> private void addListeners() {
          pager_account_cash_mail.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout_fragment_account_cash_mail));
          tablayout_fragment_account_cash_mail.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
  
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
              pager_account_cash_mail.setCurrentItem(tab.getPosition());
          }
  
          @Override
          public void onTabUnselected(TabLayout.Tab tab) {
          }
  
          @Override
          public void onTabReselected(TabLayout.Tab tab) {
          }
      });
  }
     private void setAdapter() {
          mAdapter = new CashMailPagerAdapter(this.getChildFragmentManager(), tabs_fragments_list);
          pager_account_cash_mail.setAdapter(mAdapter);
          pager_account_cash_mail.setOffscreenPageLimit(tabs_fragments_list.size());
      }
  </code></pre>
  
  <p>Additionally my code contains of addTab Function which dynamically adds the tab into the tab layout after service response and after the tabs are added I make call to these two functions.</p>
  
  <p>Whenever setAdapter line executes the debugger went into the getItem function of viewpager adapter and as soon as all the items are returns the app crashes saying :</p>
  
  <blockquote>
    <p>Process: com.foo.myapplication, PID: 17278
                                                                                       java.lang.IllegalStateException: FragmentManager is already executing transactions
                                                                                           at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1626)
                                                                                           at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
                                                                                           at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                                           at android.support.v4.view.ViewPager.populate(ViewPager.java:1240)
                                                                                           at android.support.v4.view.ViewPager.populate(ViewPager.java:1088)
                                                                                           at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5367)
                                                                                           at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1467)
                                                                                           at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
                                                                                           at android.widget.LinearLayout.onMeasure(LinearLayout.java:638)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5367)
                                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727)
                                                                                           at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1085)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5367)
                                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                                                                                           at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5367)
                                                                                           at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1467)
                                                                                           at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
                                                                                           at android.widget.LinearLayout.onMeasure(LinearLayout.java:638)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5367)
                                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5367)
                                                                                           at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1467)
                                                                                           at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
                                                                                           at android.widget.LinearLayout.onMeasure(LinearLayout.java:638)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5367)
                                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
                                                                                           at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2576)
                                                                                           at android.view.View.measure(View.java:17356)
                                                                                           at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2056)
                                                                                           at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1199)
                                                                                           at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1405)
                                                                                           at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1087)
                                                                                           at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6040)
                                                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:793)
                                                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:606)
                                                                                           at android.view.Choreographer.doFrame(Choreographer.java:575)
                                                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:779)
                                                                                           at android.os.Handler.handleCallback(Handler.java:739)
                                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                           at android.os.Looper.loop(Looper.java:135)
                                                                                           at android.app.ActivityThread.main(ActivityThread.java:5538)
                                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                                           at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)</p>
  </blockquote>