title: java.lang.IllegalStateException(Can not perform this action after onSaveInstanceState)
body: <p>I am getting this error with following message in different scenario:</p>
  
  <ul>
  <li>Activity has been destroyed and </li>
  <li>Can not perform this action after onSaveInstanceState</li>
  </ul>
  
  <p>I am writing an app where Two Activity interacting with each Other. <strong>Activity-A</strong> launch <strong>Activity-B</strong> using Intent. This <strong>Activity-B</strong> class have two fragment children. <strong>Fragment-A</strong> use public method of activity to launch another <strong>Fragment-B</strong>.</p>
  
  <pre><code>public void beginTransaction(ID id, Bundle bundle) {
  
          Fragment fragment = getFragmentItem(id);
  
          // In case this activity was started with special instructions from an Intent,
          // pass the Intent's extras to the fragment as arguments
          fragment.setArguments(bundle);
  
          // Add the fragment to the 'fragment_container' FrameLayout
          fragmentManager.beginTransaction()
          .add(R.id.fragment_container, fragment).commitAllowingStateLoss();
      }
  </code></pre>
  
  <p><strong>Fragment-B</strong> every time call <strong>finish()</strong> to kill Activity-B hence control move back to <strong>Activity-A</strong> again. And same process repeat. After doing 2-3 time I am getting:</p>
  
  <blockquote>
    <p><strong>java.lang.IllegalStateException: Can not perform this action after
    onSaveInstanceState E/AndroidRuntime( 9008):</strong>    at
    android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1354)
    E/AndroidRuntime( 9008):  at
    android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1372)</p>
  </blockquote>
  
  <p>so to avoid it I follow <a href="https://stackoverflow.com/a/10261438/2624806">https://stackoverflow.com/a/10261438/2624806</a> and it started to give me </p>
  
  <blockquote>
    <p><strong>Java.lang.IllegalStateException: Activity has been destroyed</strong>
    E/AndroidRuntime( 9235):  at
    android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1376)
    E/AndroidRuntime( 9235):  at
    android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)</p>
  </blockquote>
  
  <p>any suggestion what I am missing here.</p>
  
  <p><strong>GOT IT</strong> I got solution ..it is mistake happening in transaction for adding fragment. I was using <strong>.add</strong> instead to use <strong>.replace</strong> (as my requirement not to maintain stack) and use <strong>commitAllowTransaction</strong> to commit it. I read <a href="http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html" rel="nofollow noreferrer">http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html</a> as well and seems what I did could be costly but for normal fragment transaction mention work-around work great.</p>