0

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

I check the connected Internet and if it false, then call method openAsRoot in onCreate() Activity

private void openAsRoot(Fragment fragment) {
    manager = getSupportFragmentManager();
    manager.beginTransaction()
            .replace(R.id.container_main, fragment).commit();
}

it is perfect, but when I open the settings to turn on the Internet and then go back to my application - showed error in

    @Override
protected void onRestart() {
    if (isConnected()) {
        openAsRoot(myFragment);
    }
    super.onRestart();
}

Error "java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState"

How can I fix this ?

  • This is a pretty common issue, see: https://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-wit?rq=1 and https://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa?rq=1 – emerssso Feb 08 '18 at 16:54
  • 2
    Possible duplicate of [getting exception "IllegalStateException: Can not perform this action after onSaveInstanceState"](https://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa) – emerssso Feb 08 '18 at 16:54

0 Answers0