今天在bugly意外發(fā)現(xiàn)一個(gè)非法狀態(tài)的異常
java.lang.RuntimeException:Unable to destroy activity {com.xxx.xxx/com.xxx.xxx.mvp.orderinfo.ui.OrderInfoActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
他的意思是 這個(gè)動(dòng)作不能在onSaveInstanceState之后進(jìn)行操作
定位到代碼的具體位置是
@Override
public void hideProgress() {
if (progressDialog != null) {
progressDialog.dismiss();
}
}
是上面代碼中的progressDialog.dismiss()方法有問(wèn)題(這是一個(gè)DialogFragment)
也就是系統(tǒng)不允許dialog關(guān)閉在onSaveInstanceState之后
查了一些資料得到一些信息
java.lang.IllegalStateException異常產(chǎn)生的原因及解決辦法
錯(cuò)誤類(lèi)型大致為以下幾種:
- java.lang.IllegalStateException:Cannot forward a response that is already committed
- IllegalStateException:response already commited
- IllegalStateException:getOutputStream() has already been called for this request
IllegalStateException: Can not perform this action after onSaveInstanceState:
== 解決辦法==:onSaveInstanceState方法是在該Activity即將被銷(xiāo)毀前調(diào)用,來(lái)保存Activity數(shù)據(jù)的,如果在保存玩狀態(tài)后
再給它銷(xiāo)毀就會(huì)出錯(cuò)。解決辦法就是把dismiss()方法替換成 dismissAllowingStateLoss()
錯(cuò)誤原因:
該異常表示,當(dāng)前對(duì)客戶(hù)端的響應(yīng)已經(jīng)結(jié)束,不能在響應(yīng)已經(jīng)結(jié)束(或說(shuō)消亡)后再向客戶(hù)端(實(shí)際上是緩沖區(qū))輸出任何內(nèi)容。
Object is no longer valid to operate on. Was it deleted by another thread?
該異常表示,realmObject對(duì)象在其他線(xiàn)程已被刪除,在這個(gè)線(xiàn)程中使用的時(shí)候拋出的異常。
補(bǔ)充另一種異常情況:
這里的異常是:
java.lang.IllegalStateException
Can't change tag of fragment d{e183845 #0 d{e183845}}: was d{e183845} now d{e183845 #0 d{e183845}}
經(jīng)查,在顯示fragment的代碼中使用了:
fragment.show(getSupportFragmentManager, fragment.toString());
而這里是因?yàn)閮纱蝨oString()結(jié)果不同,導(dǎo)致不同的tag指向的是同一個(gè)fragment。
獲取fragment的tag的正確方法應(yīng)該是使用其提供的fragment.getTag()方法。