title: Add and remove fragments frequently
body: <p>I have an activity and it consists of two fragments. The app switches between one of these fragments very frequently. I am using code like this to switch between fragments,</p>
  
  <pre><code>fragmentTransaction
                  .setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left)
                  .remove(fragment2)
                  .add(R.id.common_container, fragment1)
                  .commit();
  </code></pre>
  
  <p>The above code removes fragment2 and adds fragment1. The above code works fine but when I try to switch between fragments frequently an exception showing this trace is coming up,<code>E/AndroidRuntime( 8809): java.lang.IllegalStateException: No activity
  E/AndroidRuntime( 8809):        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1054)
  E/AndroidRuntime( 8809):        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
  E/AndroidRuntime( 8809):        at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1869)
  E/AndroidRuntime( 8809):        at android.app.Fragment.performActivityCreated(Fragment.java:2067)
  E/AndroidRuntime( 8809):        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:912)
  E/AndroidRuntime( 8809):        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
  E/AndroidRuntime( 8809):        at android.app.BackStackRecord.run(BackStackRecord.java:834)
  E/AndroidRuntime( 8809):        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
  E/AndroidRuntime( 8809):        at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
  E/AndroidRuntime( 8809):        at android.os.Handler.handleCallback(Handler.java:739)
  E/AndroidRuntime( 8809):        at android.os.Handler.dispatchMessage(Handler.java:95)
  E/AndroidRuntime( 8809):        at android.os.Looper.loop(Looper.java:135)
  E/AndroidRuntime( 8809):        at android.app.ActivityThread.main(ActivityThread.java:5254)
  E/AndroidRuntime( 8809):        at java.lang.reflect.Method.invoke(Native Method)
  E/AndroidRuntime( 8809):        at java.lang.reflect.Method.invoke(Method.java:372)
  E/AndroidRuntime( 8809):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  E/AndroidRuntime( 8809):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code>
  I know that i can use replace instead of adding and removing, but there are other fragments where i cannot replace because the container is different.</p>
  
  <p>Can anyone help me ?</p>
  
  <p>Edit:
  Even replacing fragment also causes this exception</p>