square / otto

An enhanced Guava-based event bus with emphasis on Android support.
http://square.github.io/otto/
Apache License 2.0
5.17k stars 848 forks source link

Update docs for best place to register the bus #176

Open philippeluickx opened 8 years ago

philippeluickx commented 8 years ago

Based on http://stackoverflow.com/questions/19692711/illegalargumentexception-with-otto-event-bus-in-fragment-instance/19737191#19737191

I just lost 3 days and a lot of hair because of a usecase where my subscriber did not get an event. I changed my bus registration from onResume/onPause (which is used e.g. at https://github.com/square/otto/blob/master/otto-sample/src/main/java/com/squareup/otto/sample/LocationHistoryFragment.java#L33) to onStart/onStop and everything works.

felipecaldas commented 8 years ago

Didn't work for me. I had it first onReume and now at onStart. I dont get the message in my Subscribe method.

jemshit commented 8 years ago

In Fragments , registering/unregistering on onResume() and onPause() works good for me. Now i'm having trouble in DialogFragment which this didn't work. So i register/unregister on onAttach() and onDetach(). Found thread about this: http://stackoverflow.com/questions/32165006/otto-event-no-firing