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

          最近在做的一个项目,需要一个模块之间有几个小模块循环切换;因为项目视为电视开发的,在手机上运行完完全没有问题,时刻移动Android电视上以后,每到第一个小模块切换到第二个模块的时候App就会闪退,报的错误就是:java.lang.IllegalStateException: Can not perform this action after onSaveInstanceStatejava.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

再带密码中找到错误的相应位置:

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

我查了一下资料说是:commit()方法是在Activity的onSaveInstanceState()之后调用的,,使用commit提交的时候会调用到onSaveInstanceState(),而调用onSaveInstanceState()的同时系统就会回收Activity,从而造成整个App的闪退:

解决方法:只需要将commit()方法替换成commitAllowingStateLoss()就可以了;如下图所示:

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