문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top