0

I am adding fragment on onCreate using this code:

getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, myFragment)
                .addToBackStack(null).commit();

Sometimes I have to remove it on onResume using this code:

getSupportFragmentManager().beginTransaction().remove(splashFragment).commit();

getting exception: “IllegalStateException: Can not perform this action after onSaveInstanceState”

  • 1
    Possible duplicate of [getting exception "IllegalStateException: Can not perform this action after onSaveInstanceState"](http://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa) – gio Jan 13 '16 at 10:12

1 Answers1

0

Use Handler to commit the transaction as it is creating Activity state loss in the onResume method. Information came from java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState and http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html

If you are using FragmentActivity do fragment transaction in onResumeFragments() or in Activity onPostResume()

Community
  • 1
  • 1
Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46