解决Can not perform this action after onSaveInstanceState

以下为错误日志--------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();

即可解决问题。

时间: 2024-10-21 02:45:12

解决Can not perform this action after onSaveInstanceState的相关文章

解决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

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

Can not perform this action after onSaveInstanceState 解决办法

报错 java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1360) at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(Frag

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

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

Can not perform this action after onSaveInstanceState

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState     at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1323)     at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1341) 说明