Are there any advantages to switch to Otto from Broadcast events

1.5k Views Asked by At

I stumbled upon Otto, and it looks like it's used as a replacement for Broadcast events. I read the doc but, I don't understand if there are much advantages to use Otto.

3

There are 3 best solutions below

3
On BEST ANSWER

Otto should rather be compared to LocalBroadcastManager. This is because the both Otto and LocalBroadcastManager do not support inter-process communication.

Otto's pros:

  • Much less code and more readable code.
  • Complex objects can be passed through (no object serialization is required).
  • Instant value callback via @Producers.

Otto's cons:

  • Otto uses reflection, that is why it might be slower than LocalBroadcastManager if you, for instance, send integer values very frequently.
2
On

It may not matter depending on the structure of your app, but Otto also doesn't require having a Context handy to send events or register listeners.

0
On

What I don't like about using Otto instead of native instrumentation is that it requires a singleton or the ugly fetch from App's context to obtain an instance. This doesn't change when using a DI framework like dagger. Saving so much code by using annotation and using class based events instead of string based actions is a huge benefit.