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?
EventBus is an open-source library for Android and Java using the publisher/subscriber pattern for loose coupling. EventBus enables central communication to decoupled classes with just a few lines of code – simplifying the code, removing dependencies, and speeding up app development.
EventBus is a library for Java and Android that simplifies communication between various components or parts of an application. For example is in android we have several components like: Activities. Fragments.
The EventBus allows publish-subscribe-style communication between components without requiring the components to explicitly register with one another (and thus be aware of each other). It is designed exclusively to replace traditional Java in-process event distribution using explicit registration.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With