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

[java] view plaincopy print?
  1. E/AndroidRuntime(12747): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
  2. at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1314)
  3. 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()就行了,其效果是一样的。

转载于:https://www.cnblogs.com/exmyth/p/5498039.html

【转】 解决IllegalStateException: Can not perform this action after onSaveInstanceState相关推荐

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

    错误信息: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at andr ...

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

    在使用Fragment的过程中,常常会遇到在Activity的onSaveInstanceState方法调用之后,操作commit或者popBackStack而导致的crash. 因为在onSaveI ...

  3. Caused by:Java.lang.IllegalStateException:Can not perform this action after onSaveInStanceState

    出现情况: 是在使用FragmentTransition 的  Commit() 方法添加一个 Fragment的时候出现的. 问题原因: onSaveInstanceState()方法是在该Acti ...

  4. Fragment Or DialogFragment Can not perform this action after onSaveInstanceState

    转载自Fragment Or DialogFragment Can not perform this action after onSaveInstanceState 表现 可会造成app崩溃掉,具体 ...

  5. Android之提示错误Can not perform this action after onSaveInstanceState

    1 问题 主页面3个Fragment,在第三个Fragment里面开启了Activity之后,然后想跳到第一个Fragment代码如下 /*** 展示Fragment*/private fun sho ...

  6. Can not perform this action after onSaveInstanceState和重建Activity时恢复缓存的Fragmen的问题

    Fragment 在显示或者隐藏,移除是出现Can not perform this action after onSaveInstanceState  #解决办法:onSaveInstanceSta ...

  7. 【常见问题】Can not perform this action after onSaveInstanceState

    onSaveInstanceState是干什么的呢? 通过该方法保留的实例状态数据,然后借助onCreate(Bundle) or onRestoreInstanceState(Bundle),我们可 ...

  8. YII中You are not authorized to perform this action的解决方法

    当访问:TblOrders/listdetial时 YII中出现You are not authorized to perform this action的提示,是因为当前用户没有访问这个控制器下面的 ...

  9. 【Bug解决】Can‘t perform a React state update on an unmounted component. This is > a no-op, but it...

    在 React 应用程序中我们遇到以下警告消息: Can't perform a React state update on an unmounted component. This is a no- ...

  10. 20190313(已解决)对于jsp界面与action界面关系的说明_yingruiyuelin_新浪博客

    1.对于通过可以获得上面的界面,上面红色框所标注的就是从action中传过来的值 传值的条件 1)jsp与action中,在jsp有这样的名字,在action中设定了相应的属相,同时设定了get和se ...

最新文章

  1. 2015-03-06——正则表达式基础
  2. Centos-移动文件或目录-mv
  3. python定时器 循环_Python3 循环定时休息并播放音乐 (Windows)
  4. 9.21渲染错误信息 参数化配置
  5. 微软服务器系统玩游戏,微软将于2020年1月22日关闭Windows7游戏服务器
  6. Rolling element bearing diagnostics using the Case Western Reserve University data-学习笔记
  7. oracle数据库中VARCHAR2(50 CHAR) 和VARCHAR2(50) 有啥区别?
  8. WebBrowser的Cookie操作
  9. 互联网始于 50 年前的 3420 室
  10. this与$(this)的区别
  11. libevent源码深度剖析二
  12. error: could not lock config file .git/config: Permission denied/Command failed with exit 255
  13. 局域网共享工具_局域网一键共享软件2019最新版
  14. asp.net门诊收费管理系统
  15. linq左右连接查询
  16. 如何将域名解析到指定的端口(linux服务器,超级简单,图文)
  17. 如何有效的获得高质量的大规模标注数据?
  18. 卸载Visual Studio 2015并安装Visual Studio 2019
  19. 微信小程序 自动换行
  20. 使用D2D接口绘制图形

热门文章

  1. type python django models_Python菜鸟之路:Django ModelForm的使用
  2. 网页设计心得HTML心得体会3000,网页制作的心得体会
  3. 大数据用kettle还是python_Kettle学习系列之Kettle能做什么?(三)
  4. c++字符串相等比较 char* char[] string
  5. 什么是 POD 数据类型
  6. cstring 的GetBuffer() 和 ReleaseBuffer()
  7. 借助传感器用计算机测速度讲解,高中物理个性化教学的开展论文
  8. WCDMA功率控制与BER/BLER
  9. NGN学习笔记6——NGN的业务提供技术
  10. React Native系列文章