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:

 

  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()就行

了,其效果是一样的。

分类:  android solve


本文转自wanqi博客园博客,原文链接http://www.cnblogs.com/wanqieddy/p/3966758.html,如需转载请自行联系原作者

相关文章
|
4月前
|
NoSQL 编译器 API
关于thread使用的错误:pure virtual method called terminate called without an active exception
关于thread使用的错误:pure virtual method called terminate called without an active exception
54 1
|
程序员
解决报错Exception encountered during context initialization
程序员不是在去生产bug的路上,那就是在去解决bug的路上。
121 1
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState(已解决)
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState(已解决)
|
XML Java 数据格式
Exception encountered during context initialization - cancelling refresh attempt
Exception encountered during context initialization - cancelling refresh attempt:
301 0
BeanFactory not initialized or already closed - call 'refresh' before access
BeanFactory not initialized or already closed - call 'refresh' before access
267 0
|
Java Apache Spring
Exception sending context initialized event to listener instance of class
详细错误信息如下: 严重: Exception sending context initialized event to listener instance of class com.auth.spring.
1208 0
|
Java
Preference跳转activity出错Unable to find explicit activity class
使用Preference可以非常方便的实现类似设置页面这样的菜单布局,甚至可以不需写java代码。那么可以在Preference中直接添加页面跳转么?其实非常简单,在Preference添加intent标签即可
508 0
|
Java Android开发
Fragment not attached to Activity 异常
Fragment not attached to Activity 异常
Fragment Or DialogFragment Can not perform this action after onSaveInstanceState
转载自Fragment Or DialogFragment Can not perform this action after onSaveInstanceState 表现 可会造成app崩溃掉,具体日志如下: 异常如下: java.
2696 0