Otto vs LocalBroadcast:

孤街浪徒 提交于 2019-11-28 17:25:41

But on the brighter side it does support ordered broadcast

Not really. There is no sendOrderedBroadcast() on LocalBroadcastManager, and the priority on the IntentFilter does not appear to be used. If you mean "the broadcasts will be delivered in the order that I registered the receivers", that might be the current behavior, but there is no guarantee that it will stay that way.

Both Otto and LBM are within the same process space so in terms of speed i guess both would be same

They would be similar, though probably not identical.

Hence my real question is when would you use Otto if LBM does the same things

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

Personally, I'd use greenrobot's EventBus over either of those, because it offers more flexible threading models.

Both Otto and LBM are within the same process space so in terms of speed i guess both would be same .

I've found that registering Otto events are quite expensive, sometimes it takes more than 16 milliseconds to register event subscribers (That means you drop 1 FPS!). That's somewhat expected, as event subscribing in Otto is done by reflection. While for LBM, it only takes a few hundred µs only for registering, which is almost 32x faster. (Result from traceview, Samsung Galaxy S4)

But of course, using Otto can write less code, there's a trade off.

  1. otto makes code cleaner, smaller
  2. otto makes testing easier
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!