java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState问题解决

(1)我用的是fragment,在onStop但是没有onDestroy的情况下切换(replace)fragment时报 java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState错误,出现问题原因,在于我使用了FragmentTransaction.commit,解决办法:使用FragmentTransaction.commitAllowingStateLoss就不会报错了

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

E/AndroidRuntime(12747): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1314)
    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()就行

了,其效果是一样的。

参考网址:http://blog.csdn.net/acetech_sean/article/details/9275485

http://www.cnblogs.com/zgz345/archive/2013/03/04/2942553.html

时间: 2024-10-20 12:15:37

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState问题解决的相关文章

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

首先描述下所要实现的功能点: MainActivity使用Fragment实现底部菜单,底部共有四个菜单按钮,分别对应:AFragment,BFragment,CFragment,DFragment.其中AFragment是默认显示. 点击CFragment中的一个button后跳转到第二个Activity界面:SecondActivity. SecondActivity返回键有两个:button01.button02.其中button01返回的是CFragment:button02返回的是AF

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

1. 场景: 在开发过程中遇到这么一个需要,在主页点击按钮进入另一个Activity(ReadActivity),在该ReadActivity中点击一个按钮再返回主页并指定主页选中特定的Tab.主页是用FragmentTabHost + Fragment 实现.思路是通过startActivityForResult以及setResult() 以及requestCode作为标志位,是ReadActivity返回,因为还有其他的requestCode.再通过 FragmentTabHost的setC

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

在有Fragment的Activity中开启Activity出现下面这个Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceStateat android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)at android.support.v4.app.Frag

解决dialogfragment在锁屏后建立不能建立问题IllegalStateException: Can not perform this action after onSaveInstanceState

今天使用Fragment的时候,出现了这个错误 IllegalStateException: Can not perform this action after onSaveInstanceState: E/AndroidRuntime(12747): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app

解决IllegalStateException: Can not perform this action after onSaveInstanceState:

今天做项目中的支付宝功能,是在fragment中做的,在支付成功后,想切换到支付成功的页面. 结果就报错了IllegalStateException: Can not perform this action after onSaveInstanceState: 在网上找了下解决方案,将commit改成了 commitAllowingStateLoss()就没问题了,贴出原帖地址http://www.ablanxue.com/prone_7000_1.html,参考. 今天使用Fragment的时

解决IllegalStateException: Can not perform this action after onSaveInstanceState

extends:http://blog.csdn.net/ranxiedao/article/details/8214936 , http://blog.csdn.net/top_code/article/details/12614571 今天使用Fragment的时候,出现了这个错误 IllegalStateException: Can not perform this action after onSaveInstanceState: E/AndroidRuntime(12747): Cau

Android - IllegalStateException: Can not perform this action after onSaveInstanceState

IllegalStateException: Can not perform this action after onSaveInstanceState 本文地址:http://blog.csdn.net/caroline_wendy 参考:http://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa/1026143

IllegalStateException: Can not perform this action after onSaveInstanceState 错误解决方法

使用handler 更新主activity中的碎片fragment是在使用FragmentTransition的 commit方法添加一个Fragment的时候报IllegalStateException: Can not perform this action after onSaveInstanceState. 问题原因: 因为 onSaveInstanceState方法 是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存完状态后再用commit方法给它添加Fr

IllegalStateException: Can not perform this action after onSaveInstanceState

今天做项目的导航框架的时候遇到一个bug,框架如上图所示: 这个bug很奇怪,第一次进入运行.无论你怎么点击都OK!但是,当你退出去再进来的时候点击就会报上面的错误!在网上找了找,像这样的一个错误会有千奇百怪的方式出现!但是,一句"该操作不能执行在onSaveInstanceState()之后"却是一样的.像这种错误不是通用的,它相当于是一个很大的错误集,里面有很多报错的方式! 下面分析一下我的错误: 我的这个侧滑的左侧点击任一个item就会在右边位置显示该item对应的内容.这个效果