IllegalArgumentException with Otto Event bus in Fragment instance

后端 未结 1 665
自闭症患者
自闭症患者 2020-12-24 09:53

I am using Otto Event bus to subscribe to certain events in a ListFragment. The bus instance is stored and created in an subclass of Application, in other words, it bus shou

相关标签:
1条回答
  • 2020-12-24 10:33

    I had same issue. Instance stayed registered in the bus in some cases. A reliable solution is to use onStart()/onStop() methods to register/unregister receivers. This is what Square guys suggest too. They explain it like this. If activity is in background, it does not need to refresh UI anyway, because UI is not visible. Once activity comes foreground, it will receive update and refresh UI.

    Update: as mentioned in the comments, registering / unregistering in onResume()/onPause() can cause some undesired effects in certain cases like if there is a dialog shown over your activity, then activity gets paused and is not able to receive events anymore.

    0 讨论(0)
提交回复
热议问题