fragment/dialogfragment异常:Can not perform this action after onSaveInstanceState
来源:互联网 发布:php api接口 编辑:程序博客网 时间:2024/06/07 13:29
项目在测试的时候未出现崩溃,但是上线之后奔溃日志中发现有相当数量的报错信息如下:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1538)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1556)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:696)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:662)
at android.support.v4.app.DialogFragment.show(DialogFragment.java:143)
at com.hsl.stock.view.activity.NewWebActivity
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
根据异常信息Can not perform this action after onSaveInstanceState,可以了解到异常原因:在onSaveInstanceState行为之后,app执行某个不能响应的行为而导致异常发生。
查看对应的错误信息发现时fragment的commit()方法造成的崩溃.查看官网解决办法是将commit()方法换乘commitAllowingStateLoss ()方法.具体查看
https://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss()
关于commitAllowingStateLoss ()方法的解释:
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()就行了,其效果是一样的。或者有使用dialogfragment的show方法报此异常的可使用
getFragmentManager().beginTransaction().add(aaa, “aaa”).commitNowAllowingStateLoss();
dialogfragment的dismiss()方法则换乘dismissAllowingStateLoss();
之后崩溃日志中就不会再报错误了.
- fragment/dialogfragment异常:Can not perform this action after onSaveInstanceState
- Fragment Or DialogFragment Can not perform this action after onSaveInstanceState
- Fragment Or DialogFragment Can not perform this action after onSaveInstanceState
- fragment 异常IllegalStateException: Can not perform this action after onSaveInstanceState
- Can not perform this action after onSaveInstanceState(fragment异常)
- Fragment异常:Can not perform this action after onSaveInstanceState
- DialogFragment - 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 出现Can not perform this action after onSaveInstanceState
- Fragment错误:IllegalStateException: Can not perform this action after onSaveInstanceState
- Fragment Can not perform this action after onSaveInstanceState
- Fragment中出现Can not perform this action after onSaveInstanceState
- 解决fragment错误 Can not perform this action after onSaveInstanceState
- fragment使用时 Can not perform this action after onSaveInstanceState
- Fragment坑之Can not perform this action after onSaveInstanceState
- Fragment系列之Can not perform this action after onSaveInstanceState
- Fragment Can not perform this action after onSaveInstanceState
- 112.hdu--1050--Moving Tables
- 手动内存管理转ARC项目实战
- .NET基础之总纲——学习.NET要学什么
- 推荐一个免费的空间
- 1 twoSum
- fragment/dialogfragment异常:Can not perform this action after onSaveInstanceState
- Win7下配置nginx-1.10.3+php-7.1.1-nts-Win32-VC14-x64 Win7配置Nginx+PHP7
- 关于查看OCX控件接口和AdobeReader,FoxitReader在页面中展示PDF文件
- SystemUI之USB1(kernel->Framework UEvent)
- 快速排序-python
- Android_UI:TextView + TextLinkify + TextSwitcher
- CSS优先级应用
- CorelDRAW有哪些常用的快捷键
- Spring注解@Autowired和@resource的区别