`

解决IllegalStateException: Can not perform this action after onSaveInstanceState

阅读更多
转自http://www.cnblogs.com/zgz345/archive/2013/03/04/2942553.html

今天使用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.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1314) 
        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()就行

了,其效果是一样的。
分享到:
评论

相关推荐

    action-buffer:提供了在处理后台任务时避免片段过渡期间出现 IllegalStateException 的示例

    这个存储库提供了一种在处理片段传输和后台任务时避免“java.lang.IllegalStateException:Can not perform this action after onSaveInstanceState”的方法。 您可以在的非常权威的阅读有关该问题和可能的解决方案...

    java.lang.IllegalStateException: Cannot call sendError() after the response has

    在Java的Web开发中,`java.lang.IllegalStateException: Cannot call sendError() after the response has been committed` 是一个常见的错误,通常发生在尝试在HTTP响应已经发送到客户端之后调用`sendError()`方法...

    java.lang.IllegalStateException: getOutputStream() has already解决办法

    纠结了半天的 java.lang.IllegalStateException: getOutputStream() has already。这个问题困扰了半天,在网上查阅了大量资料 出这个错误一般就是下面2个.....

    关于IllegalStateException: The specified child already has a parent.

    IllegalStateException: The specified child already has a parent.我的博客中有文章讲解

    Java异常之—-Caused by: java.lang.IllegalStateException: Method has too many Body parameters

    异常:Caused by: java.lang.IllegalStateException: Method has too many Body parameters Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract ...

    spring入门好教程

    Spring框架,由Rod Johnson创立并由Interface21公司推广,自诞生以来,它就致力于简化Java企业级应用(J2EE)的开发,提供了一种非侵入式的解决方案,极大地提高了开发效率。它的目标不仅仅是解决单一层次的问题,...

    java.lang.IllegalStateException: OutputStream already obtain

    标题 "java.lang.IllegalStateException: OutputStream already obtain" 涉及到的是Java编程中的一个常见错误,特别是当处理I/O流时。这个异常通常在尝试获取已经存在的OutputStream实例时抛出,表明该输出流已经被...

    spark 核心架包

    解决java.lang.IllegalStateException: unread block data的架包

    ListView后台更新报错:java.lang.IllegalStateException

    java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but...

    jacob使用说明终极吐血版

    **Jacob使用说明终极吐血版** ... ## 1.... ...JNI允许Java代码调用本地(Native)代码,也就是非Java语言编写的代码,如C++或C。...## 2....首先,你需要下载Jacob的JAR文件和相应的DLL库。DLL库根据你的操作系统位数(32位或64...

    Jnative1.4_java调用动态库所需jar

    Java是一种高级编程语言,通常用于开发跨平台的应用程序。然而,有时我们可能需要在Java程序中调用操作系统底层的动态链接库(DLLs on Windows,SOs on Linux,dylibs on macOS),以便利用C、C++等语言编写的高性能...

    tomcat启动的错误

    这些问题如果不能及时解决,将会影响到项目的正常运行与部署。本文将对“tomcat启动的错误”这一主题进行深入探讨,并结合具体的错误信息来分析其原因及解决方案。 #### 错误描述:“Could not load ...

    java dubbo admin 2.5.3 + jdk1.7

    java dubbo admin 2.5.3 + jdk 1.7 亲试 好用 ... java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

    For gd&t not affected - when to revise dwg guidelines 3-21-02.ppt

    标题提及的“For gd&t not affected - when to revise dwg guidelines 3-21-02.ppt”指的是在GD&T未受工程变更影响时,如何判断是否需要更新图纸的指导原则。描述进一步强调了当GD&T不受工程变更影响时,确定图纸...

    xfire访问webservice客户端用到的jar包

    在Java开发中,Web服务(Web Service)是一种标准的接口,允许不同系统之间进行通信,而XFire是早年流行的一款用于构建和消费Web服务的开源框架。它使用SOAP(简单对象访问协议)和XML(可扩展标记语言)作为基础,...

    oop object , for apple ios developer

    ### 面向对象编程与Objective-C:苹果iOS开发者指南 #### 一、概述 面向对象编程(Object-Oriented Programming, ...深入理解Objective-C不仅可以帮助开发者更好地理解苹果平台的技术栈,还能提升其解决问题的能力。

    Failed to load ApplicationContext

    java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate....

    powerbuilder

    ### PowerBuilder 中从 Excel 导入数据到 DataWindow 的实现方法 #### 标题解析: 在 PowerBuilder 开发环境中,经常需要将外部数据源(如 Excel 文件)中的数据导入到程序内部的数据展示组件(DataWindow)中进行...

Global site tag (gtag.js) - Google Analytics