title: Activity has been destroyed while adding a Fragment to a ViewPager
body: <p>I'm creating a <code>ViewPager</code> with a dynamic number of Fragments, I provide the <code>FragmentStatePagerAdapter</code> of this <code>ViewPager</code> with a list of Fragments as in the following:</p>
  
  <pre><code>public class LightPageAdapter extends FragmentStatePagerAdapter {
      private List&lt;Fragment&gt; myFragments;
  
      public LightPageAdapter(FragmentManager fragmentManager, List&lt;Fragment&gt; fragments) {
          super(fragmentManager);
  
          myFragments = fragments;
  
      }
  
     public Fragment getItem(int i) {
  
          return myFragments.get(i);
  
      }
  
     @Override
     public int getCount() {
  
          return myFragments.size();
  
      }
  }
  </code></pre>
  
  <p>the fragments list is obtained when clicking some <strong>button</strong> on certain <code>Fragment</code>, So, i added the following method to this <code>Fragment</code> in order to adding this fragments list to the <code>FragmentStatePagerAdapter</code>:</p>
  
  <pre><code>public void fargmenting(List&lt;Fragment&gt; fragments){
  
     ViewPager view_pager = (ViewPager) MyFragment.view.findViewById(R.id.lighting_pager);
     view_pager.setAdapter(new LightPageAdapter(getChildFragmentManager(), fragments)); // this is where I'm getting the Exception
  
  }
  </code></pre>
  
  <p><strong>Hint</strong>:
   in my app I'm using <code>VerticalViewPager</code> not <code>ViewPager</code> but it's a <strong>library</strong> with the same behaviour of the <code>ViewPager</code> but with some modification that wouldn't affect the overall process.</p>
  
  <p>And this is the <strong>Log Error</strong>:</p>
  
  <pre><code>05-07 11:51:02.404: E/AndroidRuntime(3174): FATAL EXCEPTION: main
  05-07 11:51:02.404: E/AndroidRuntime(3174): java.lang.IllegalStateException: Activity has been destroyed
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1365)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:578)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:161)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.automation.standards.VerticalViewPager.populate(VerticalViewPager.java:965)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.automation.standards.VerticalViewPager.populate(VerticalViewPager.java:811)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.automation.standards.VerticalViewPager.setAdapter(VerticalViewPager.java:334)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.automation.fragments.MyFragment.fargmenting(Lighting_Right.java:92)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.automation.isolace.Lighting.assign_vertical_gangs_swipping(Lighting.java:502)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.automation.isolace.Lighting.select_room(Lighting.java:403)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.automation.isolace.Lighting$11.onClick(Lighting.java:351)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.view.View.performClick(View.java:4084)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.view.View$PerformClick.run(View.java:16966)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.os.Handler.handleCallback(Handler.java:615)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.os.Handler.dispatchMessage(Handler.java:92)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.os.Looper.loop(Looper.java:137)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at android.app.ActivityThread.main(ActivityThread.java:4745)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at java.lang.reflect.Method.invoke(Method.java:511)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  05-07 11:51:02.404: E/AndroidRuntime(3174):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>