解决IllegalStateException: Can not perform this action after onSaveInstanceState今天使用Fragment的时候,出现了这个错误 IllegalStateException: Can not perform this action after onSaveInstanceState:
是在使用FragmentTransition的 commit方法添加一个Fragment的时候出现的,后来在官网找到了相关的 说明:http://developer./reference/android/app/FragmentTransaction.html#commitAllowingStateLoss() public abstract int commitAllowingStateLoss ()
Added in API level 11
Like onSaveInstanceState方法是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存玩状态后 再给它添加Fragment就会出错。解决办法就是把commit()方法替换成 commitAllowingStateLoss()就行 了,其效果是一样的。 |
|
来自: JUST SO LAZY > 《java\android》