Fragment IllegalStateException: Can not perform this action after onSaveInstanceState
来源:互联网 发布:机锋网推荐的淘宝 编辑:程序博客网 时间:2024/05/20 21:41
http://blog.csdn.net/top_code/article/details/12614571
在使用Fragment的FragmentTransaction commit 时候经常会碰到下面的错误:
- java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
- at android.support.v4.app.FragmentManagerImpl.checkStateLoss(Unknown Source)
- at android.support.v4.app.FragmentManagerImpl.enqueueAction(Unknown Source)
- at android.support.v4.app.BackStackRecord.commitInternal(Unknown Source)
- at android.support.v4.app.BackStackRecord.commit(Unknown Source)
- at com.yulore.yellowpage.DialLogActivity.a(Unknown Source)
- at com.yulore.yellowpage.fragment.x.handleMessage(Unknown Source)
- at android.os.Handler.dispatchMessage(Handler.java:99)
- at android.os.Looper.loop(Looper.java:137)
- at android.app.ActivityThread.main(ActivityThread.java:4797)
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:511)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
- at dalvik.system.NativeStart.main(Native Method)
查看Developer文档 commit 方法说明
解决办法
把commit()方法替换成 commitAllowingStateLoss()
- ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
- if (this.isFinishing()) { //判断Activity是否还存在
- return;
- }
- ft.commitAllowingStateLoss();
- // ft.commit();
20. 在debug带有android.support.v4的包时,结果出现下面的错误:
05-10 15:47:09.850: E/AndroidRuntime(12744): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
比较完整的stack如下:
1
05
-
10
15
:
47
:
06.470
: W/dalvikvm(
12744
): threadid=
1
: thread exiting with uncaught exception (group=
0x40a4b1f8
)
2
05
-
10
15
:
47
:
09.850
: E/AndroidRuntime(
12744
): FATAL EXCEPTION: main
3
05
-
10
15
:
47
:
09.850
: E/AndroidRuntime(
12744
): java.lang.IllegalStateException: Can not perform
this
action after onSaveInstanceState
4
05
-
10
15
:
47
:
09.850
: E/AndroidRuntime(
12744
): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:
1299
)
5
05
-
10
15
:
47
:
09.850
: E/AndroidRuntime(
12744
): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:
1310
)
6
05
-
10
15
:
47
:
09.850
: E/AndroidRuntime(
12744
): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:
541
)
7
05
-
10
15
:
47
:
09.850
: E/AndroidRuntime(
12744
): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:
525
)
8
05
-
10
15
:
47
:
09.850
: E/AndroidRuntime(
12744
): at android.support.v4.app.DialogFragment.show(DialogFragment.java:
123
)
http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-h
我看到上面有提到onSaveInstanceState(),于是就重写了下这个.像上面说的不能调用super.我调用了,而且居然就tmd没有错误提示了..
19.05-10 16:08:43.190: E/AndroidRuntime(14243): java.lang.IllegalStateException: addToBackStack() called after commit()
0 0
- 解决Fragment IllegalStateException: Can not perform this action after onSaveInstanceState
- Fragment IllegalStateException: Can not perform this action after onSaveInstanceState
- fragment 异常IllegalStateException: Can not perform this action after onSaveInstanceState
- Fragment错误:IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- Android 异常 IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- IllegalStateException: Can not perform this action after onSaveInstanceState解决办法
- java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- IllegalStateException: Can not perform this action after onSaveInstanceState
- 解决异常IllegalStateException: Can not perform this action after onSaveInstanceState
- clientDataSet和TDataSetProvider对数据的操作
- 多线程编程Peterson算法
- android root权限破解分析
- 陈数揍渣男惩小三 《男闺蜜》《歌手》周末大战
- eclipse常用快捷键 --10大常用快捷键 可以提高不小的工作效率哦
- Fragment IllegalStateException: Can not perform this action after onSaveInstanceState
- 在Windows下搭建开发Linux程序的环境
- unity使用line renderer画线
- 如何自己编译wireless tool
- c与c++中struct区别
- IOS开发调用系统相机和打开闪光灯
- Redmine任务管理工具
- 盛大啊啊啊啊啊发艾丝凡
- LDD3 勘误(P270,第三段)