解決IllegalStateException: Can not perform this action after onSaveInstanceState
今天使用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的時候出現的,後來在官網找到了相關的
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()就行了,其效果是一樣的。
相關文章
- 解決okhttp報java.lang.IllegalStateException: closed,java.lang.IllegalStateException: closedHTTPJavaException
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed解讀JavaExceptionErrorMIT
- Error: The action can not be performed because ...could not be locked?ErrorORM
- ORA-38301:can not perform DDL/DML over objects in Recycle BinORMObject
- onSaveInstanceState和onRestoreInstanceState詳解REST
- CRS can not Start After Node Reboot (文件 ID 733260.1)boot
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解決方案JavaException
- Error: The action can not be performed because the selected records are not eligibleErrorORM
- ISM or DISM Misconfiguration can Slow Down Oracle Database Perform_1472108.1OracleDatabaseORM
- Supervisor 解決 can't find command *
- 解決can't find -lGL的問題
- 解決Can not allocate log問題的方法
- Activity onSaveInstanceState(Bundle)
- cordova 解決can’t not find moudle " plugman platform ios"PlatformiOS
- startActivityForResult()和onSaveInstanceState()用法
- Struct FORM ACTION 無法解決動態賦值?StructORM賦值
- 一個異常org.apache.jasper.JasperException: java.lang.IllegalStateException: No output folder:的解決...ApacheExceptionJava
- How to Perform a Healthcheck on the DatabaseORMDatabase
- 報錯(已解決)Command timed out after no timeout
- "ScrollView can host only one direct child"問題解決View
- Only a type can be imported. classname resolves to a package的解決ImportPackage
- can't assign requested address 錯誤解決
- linux上“rman can't open target”問題解決Linux
- Action呼叫字首詳解
- java.lang.IllegalStateException: closedJavaException
- 如何解決 After Effects報警
- ajax呼叫,action返回的中文為亂碼的解決方案
- How to Perform a Health Check on the DatabaseORMDatabase
- 完美解決stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.ErrorPython
- Mysql:Variable 'XXXt' can't be set to the value of 'NULL'解決MySqlNull
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- FileZilla:425 Can't open data connection for transfer of解決辦法
- mysql:Variable 'character_set_client' can't be set to the value of 'NULL'解決MySqlclientNull
- MySQL 5.7半同步複製after sync和after commit詳解MySqlMIT
- 解決drbd不能啟動問題(Can not load the drbd module.)
- 解決Android 8 0的Only fullscreen opaque activities can request orientatioAndroidOpaque
- 解決svnserve: Can't bind server socket: Address already in useServer
- Variable 'character_set_client' can't be set to the value of Null的解決方法clientNull