【转】 解决IllegalStateException: Can not perform this action after onSaveInstanceState

时间:2021-10-29 00:17:22

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

  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()就行了,其效果是一样的。

【转】 解决IllegalStateException: Can not perform this action after onSaveInstanceState的更多相关文章

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

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

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

    今天做项目中的支付宝功能,是在fragment中做的,在支付成功后,想切换到支付成功的页面. 结果就报错了IllegalStateException: Can not perform this act ...

  3. IllegalStateException: Can not perform this action after onSaveInstanceState

    http://www.cnblogs.com/zgz345/archive/2013/03/04/2942553.html 今天使用Fragment的时候,出现了这个错误 IllegalStateEx ...

  4. java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState问题解决

    (1)我用的是fragment,在onStop但是没有onDestroy的情况下切换(replace)fragment时报 java.lang.IllegalStateException: Can n ...

  5. Android 错误:IllegalStateException: Can not perform this action after onSaveInstanceState

    今天做Fragment切换.状态保存功能的时候,出现了这个错误: E/AndroidRuntime(12747): Caused by: java.lang.IllegalStateException ...

  6. java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState解决?

    做项目到最后整合的时候测试的时候发现  切换tab更换fragment的时候抛出了这个异常,根据异常信息Can not perform this action after onSaveInstance ...

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

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

  8. Can not perform this action after onSaveInstanceState

    java.lang.RuntimeException: Unable to resume activity {com.tongyan.nanjing.subway/com.tongyan.struct ...

  9. android异常:Can not perform this action after onSaveInstanc

    extends:http://zhiweiofli.iteye.com/blog/1539467 本人某个android项目开发阶段一直运行良好,直到上线前夕,在某款跑着android 4.03系统的 ...

随机推荐

  1. SQLServer 事务隔离级别

    MSSQL 事务级别 分类: 数据库2012-12-28 11:17 1050人阅读 评论(0) 收藏 举报 事务 级别 等级优化数据库 一个系统项目做大了,就会遇到性能问题.数据库的优化将是解决性能 ...

  2. 第一次sprint团队贡献分改

    201306114322 邵家文 50分 201306114319 陈俊金 10分 201306114320 李新    10分 201306114324 朱浩龙 10分

  3. WCF全面解析第一章 WCF 简介

    1.WCF中的 "A","B","C" 介绍 我们先看个生活中的例子,某一天,公司的领导让你去送一份合同文件,送文件的过程你可以选择的交通方 ...

  4. iOS 设计模式之抽象工厂

    设计模式是程序提升的必备知识,这里说下iOS怎样实现抽象工厂设计模式.本文是看过oc编程之道这本的抽象工厂这章后写出的,假设不明确原理能够看看那本书. TestView.h首先创建一个视图 // // ...

  5. Eclipse安装SVN插件的方法( 手动安装)

    Eclipse Svn 插件CSDN下载地址:http://download.csdn.net/source/3143260  手动安装: 1.在Eclipse根目录下建一个任意文件夹(如plugin ...

  6. java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with this activity

    错误描述:java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with t ...

  7. 使用Physics_Body_Editor获得json文件的类

    [转自]:http://www.cocoachina.com/bbs/read.php?tid=209290 工具介绍,json文件获得方法,请参考原帖 MyBodyParser.h // // My ...

  8. Android数据存储三剑客——SharedPreferences、File、SQLite

    Android中常用的数据存储一般有三种方式:SharedPreferences.文件和SQLite数据库,用来保存需要长时间保存的数据.本文将通过几个具体的小实例来讲解这三种方式的具体实现. 数据存 ...

  9. PHP框架学习之Laravel安装

    自从接触PHP以来一直使用Yii,感觉Yii实现功能比较简单,是一个很不错的框架.最近由于工作的原因开始研究Laravel5,不得不说我在第一步安装就被坑着了,下面就是我痛苦的学习成果.Laravel ...

  10. JS学习笔记Day8

    一.内置函数Math 1.Math 1)Math.abs() 求绝对值 2)Math.PI 圆周率 2.求近似值: 1)Math.round() 四舍五入(负数: >0.5 进一 <=0. ...