解决Can not perform this action after onSaveInstanceState

文章详细介绍了在Android应用中使用FragmentManager进行界面刷新时遇到的IllegalStateException错误,及其解决方法——使用commitAllowingStateLoss()替代commit()。适用于遇到类似错误时的开发者。
摘要由CSDN通过智能技术生成

以下为错误日志--------start--------

01-08 23:43:19.622: E/AndroidRuntime(961): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { }} to activity {com.biggod/com.biggod.activity.MainActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState01-08 23:43:19.622: E/AndroidRuntime(961): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)01-08 23:43:19.622: E/AndroidRuntime(961): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)01-08 23:43:19.622: E/AndroidRuntime(961): at android.app.ActivityThread.access$2000(ActivityThread.java:117)01-08 23:43:19.622: E/AndroidRuntime(961): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)01-08 23:43:19.622: E/AndroidRuntime(961): at android.os.Handler.dispatchMessage(Handler.java:99)01-08 23:43:19.622: E/AndroidRuntime(961): at android.os.Looper.loop(Looper.java:123)01-08 23:43:19.622: E/AndroidRuntime(961): at android.app.ActivityThread.main(ActivityThread.java:3683)01-08 23:43:19.622: E/AndroidRuntime(961): at java.lang.reflect.Method.invokeNative(Native Method)01-08 23:43:19.622: E/AndroidRuntime(961): at java.lang.reflect.Method.invoke(Method.java:507)01-08 23:43:19.622: E/AndroidRuntime(961): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)01-08 23:43:19.622: E/AndroidRuntime(961): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)01-08 23:43:19.622: E/AndroidRuntime(961): at dalvik.system.NativeStart.main(Native Method)01-08 23:43:19.622: E/AndroidRuntime(961): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState01-08 23:43:19.622: E/AndroidRuntime(961): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1327)01-08 23:43:19.622: E/AndroidRuntime(961): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1338)01-08 23:43:19.622: E/AndroidRuntime(961): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)01-08 23:43:19.622: E/AndroidRuntime(961): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)01-08 23:43:19.622: E/AndroidRuntime(961): at com.biggod.activity.MainActivity.onActivityResult(MainActivity.java:88)01-08 23:43:19.622: E/AndroidRuntime(961): at android.app.Activity.dispatchActivityResult(Activity.java:3908)01-08 23:43:19.622: E/AndroidRuntime(961): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)01-08 23:43:19.622: E/AndroidRuntime(961): ... 11 more


end-------------------------

遇到这个问题是我在onActivityResult方法中,执行以下语句

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_contiainer,new OwnFragment()).commit();


OwnFragment是我自己写的fragment。我是为了重新刷新界面而执行该语句。就出现了上述错误。

解决方法:

将commit()方法,替换为

commitAllowingStateLoss();

即:

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_contiainer,new OwnFragment()).commitAllowingStateLoss();

即可解决问题。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值