25

I understand how to use Intents to communicate with the system/other apps. I understand how to use Intents within the same App. I also understand how to use Otto to communicate within the same App.

What are the Pro/Cons of using Otto vs. Intents to communicate between my Activities/Services?

Martin S.
  • 556
  • 4
  • 11
  • 3
    This question shouldn't be closed. The resulting answer was very informative and exactly answered my question. The answer was based on fact based pros and cons, so this question didn't generate primarily opinion-based answers. – Jade Aug 13 '14 at 17:30

1 Answers1

39

Pros for using Otto:

  • You get to design your own event types, versus having to use custom actions or something to distinguish one Intent from another

  • Everything is within your own process (contrast with startActivity() and kin, which always involve IPC, even if the activity you are starting is in your own app), for speed and security

  • A bit less coding, as you aren't having to instantiate IntentFilter or BroadcastReceiver objects

  • It offers the producer pattern (as a quasi-replacement for sticky broadcasts)

  • Being not part of the OS, it has the potential to be updated more frequently

Cons for using Otto:

  • It cannot start an activity

  • It cannot start a service

  • It cannot bind to a service

  • It cannot send a broadcast

  • It cannot be used in a PendingIntent or for any true IPC

IOW, the true comparison for Otto is with LocalBroadcastManager, not with the general use of Intents.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Thanks. So compared to LocalBroadCastManager it still has many of the Pros but none of the Cons? – Martin S. Jun 26 '13 at 11:03
  • 1
    @MartinS.: In comparison to `LocalBroadcastManager`, the pros are all valid except the second one (since that is also true of `LocalBroadcastManager`). You are correct that the cons all fall away. – CommonsWare Jun 26 '13 at 11:05
  • @CommonsWare and last one too, because LocalBroadcastManager is part of support library and it is included just in your apk. – Henry Pootle Jun 09 '15 at 09:34
  • @CommonsWare knows his onions! – Subby Jun 22 '15 at 09:16
  • Is it better than LBM? – Bytecode May 16 '16 at 08:29
  • @Bytecode: As [I noted almost two years ago](http://stackoverflow.com/questions/17317922/using-intents-or-an-event-bus-to-communicate-within-the-same-app/17318265?noredirect=1#comment25118565_17318265), when comparing Otto to `LocalBroadcastManager`, Otto has all of the "pros" listed in the answer except the second one (which is also true for `LocalBroadcastManager`). All of the cons go away, as both Otto and `LocalBroadcastManager` share those limitations. – CommonsWare May 16 '16 at 10:44
  • @CommonsWare : Can I move my LBM code to EventBus? What you suggest – Bytecode May 16 '16 at 11:47
  • @Bytecode: "Can I move my LBM code to EventBus?" -- you could, but I do not know if it is worth the change. The benefits that I cite are all programming benefits, not runtime benefits. – CommonsWare May 16 '16 at 11:56