Otto vs LocalBroadcast:

I am a big fan of open source contributions made for the Android community and have been studying their latest contribution Otto (event bus)

http://square.imtqy.com/otto/

Digging deeper, I see that Otto uses reflection, and there is no ordered broadcast (a template in which an unprocessed message is transmitted from one receiver to the next receiver, listening to the same event). Otto believes in more fire and forget the model.

Now the android has a LocalBroadcastManager (LBM) in its v4 support library, which performs the same task, although it is more cumbersome and has more restrictions on the objects being transferred. But on the brighter side, he maintains orderly broadcasting and is more like a normal broadcast.

Both Otto and LBM are in the same process space, so in terms of speed, I assume that both will be the same. The only real difference that I could see is that Otto allows you to define custom events, and you don't need to serialize / Parcel Objects.

Therefore, my real question is: when do you use Otto if LBM does the same.

References:

http://nick.perfectedz.com/otto-event-system/

Use intent or event bus to communicate in one application

https://plus.google.com/107049228697365395345/posts/6j4ANWngCUY

+43
android android-intent otto
Apr 04 '14 at 19:11
source share
3 answers

But on the brighter side, it supports streamlined broadcasting.

Not really. There LocalBroadcastManager no sendOrderedBroadcast() in IntentFilter , and priority on IntentFilter not used. If you mean that "the broadcasts will be delivered in the order in which I registered the receivers", this may be the current behavior, but there is no guarantee that it will remain so.

Both Otto and LBM are in the same process space, so in terms of speed, I assume that both will be the same

They would be similar, although probably not identical.

So my real question is: when do you use Otto if LBM does the same

Comparing the two, Otto has a cleaner API, IMHO.

Personally, I used greenrobot EventBus for any of them, because it offers more flexible stream models.

+36
Apr 04 '14 at 19:22
source share

Both Otto and LBM are in the same process space, so in terms of speed, I assume that both will be the same.

I found that recording Otto events is quite expensive, sometimes it takes more than 16 milliseconds to register event subscribers (this means you drop 1 FPS!). This was somewhat expected, since the event signed at Otto is carried out by reflection. Although LBM only requires a few hundred microseconds for registration only, which is almost 32 times faster. (Result from traceview, Samsung Galaxy S4)

But of course, using Otto can write less code, there is a trade-off.

+5
Mar 21 '16 at 6:06
source share
  • otto makes code cleaner, less
  • otto simplifies testing.
0
Jun 06 '16 at 12:34
source share



All Articles