天天看點

EventBus遇到的BUG “IllegalStateException: Activity has been destroyed” in fragment trasaction

 由于項目中有大量的回調,就使用EventBus.結果出現了一個BUG。

至于具體的用法我就不介紹了,下面主要介紹使用EventBus時遇到的Bug.

我在使用Activity + fragment 的時候,發現在頁面多次傳回之後,應用崩潰。

檢視log日志,提示:

“IllegalStateException: Activity has been destroyed” in fragment trasaction

就去百度 “Activity has been destroyed”,搜尋結果很多,但是都沒有效果。 把問題說給同僚聽後,有人說可能記憶體洩漏,導緻記憶體不足, Activity就被銷毀了。

然後檢查,發現 EventBus 忘了 unregister(); 在代碼中加了 EventBus.getDefault().unregister(this) 之後,BUG消失;