解决IllegalStateException: Can not perform this action after onSaveInstanceState

来源:互联网 发布:fluent软件官方下载 编辑:程序博客网 时间:2024/06/06 09:13


转载至:http://blog.csdn.net/ranxiedao/article/details/8214936


今天使用Fragment的时候,出现了这个错误 IllegalStateException: Can not perform this action after onSaveInstanceState:

[java] view plain copy
print?
  1. E/AndroidRuntime(12747): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState  
  2.     at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1314)  
  3.     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1325)  

是在使用FragmentTransition的 commit方法添加一个Fragment的时候出现的,后来在官网找到了相关的

说明:http://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss()

public abstract int commitAllowingStateLoss ()                                    Added in API level 11

Like commit() but allows the commit to be executed after an activity's state is saved. This is dangerous 

because the commit can be lost if the activity needs to later be restored from its state, so this should 

only be used for cases where it is okay for the UI state to change unexpectedly on the user.

大致意思是说我使用的 commit方法是在Activity的onSaveInstanceState()之后调用的,这样会出错,因为onSaveInstanceState

方法是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存玩状态后再给它添加Fragment就会出错。解决办法就

是把commit()方法替换成 commitAllowingStateLoss()就行了,其效果是一样的。



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 买车型号错了怎么办 沃出行不退押金怎么办 钢铁雄心4人力0怎么办 钢铁雄心4没工厂怎么办 钢铁雄心4锁区怎么办 qq超市金币满了怎么办 旋转轮胎2车翻了怎么办 轮胎里面卡进小石子应该怎么办 手游吃鸡模拟器已经到达上限怎么办 逆战场手游模拟器黑屏怎么办 欧洲卡车2翻车了怎么办 卧式注塑机锁模久了打不开怎么办 欧洲卡车2困了怎么办 欧卡2没油了怎么办 欧卡2车卡住了怎么办 欧卡2车子卡住了怎么办 做题手感变差怎么办 吃鸡游戏掉帧怎么办 买了俄区游戏怎么办 战地1子弹用完了怎么办 1kb彩信点开了怎么办 玩地球末日卡顿怎么办 电脑显示不亮了怎么办 电脑玩游戏显卡停止运行怎么办 ie浏览器打开就停止工作怎么办 蝙蝠侠阿甘骑士卡顿怎么办 捷豹钥匙没电了怎么办 车钥匙没电 汽车报警怎么办 东西卡在门锁里怎么办 锁芯里面有东西怎么办 有东西卡在锁里怎么办 锁里面卡了牙签怎么办 塑料卡在锁里怎么办 门锁被牙签堵了怎么办 锁子里面卡东西怎么办 东西卡在锁里怎么办 开车门碰到旁边车门怎么办 美团退款后 物品怎么办 倒车影像是反的怎么办 荒野行动cp版玩着玩着关机怎么办 王者荣耀点击开始游戏就闪退怎么办