I am confused about the difference between EventBus and RxJava in android. I need to implement one of them for my issue about notifying some components when some changes have been done, so that they can update their state.
Also, I read that EventsBus has became deprecated over RxJava and I don't know if this information is true or not.
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.
RxBus - An event bus by ReactiveX/RxJava/ReactiveX/RxAndroid. This is an event bus designed to allowing your application to communicate efficiently.
EventBus
and RxJava
are different in their nature.
EventBus
is just a bus
as the name suggest - it provides the mechanism to subscribe and publish events to the "bus", without you caring how the wiring is done, what this "bus" actually is, etc. In the context of Android, the EventBus
is just an easier way to deal with sending and receiving Broadcast
messages with less boilerplate.
RxJava
on the other hand is much much more powerful than that. Yes, you can subscribe and publish events, but you have far more control over the process - frequency, on which thread everything happens, etc. The main power of RxJava
(in my opinion) is that you can manipulate the data being published very easy, using some of its tons of operators
.
To sum up - if you only care about publishing some events and performing some actions when received - you'd probably be better off using the simplest of the two, namely some kind of Bus
, or even plain old BroadcastReceiver
s. If you will also benefit of transforming the data, handling threading or simplified error handling - go for the RxJava
approach. Just keep in mind that RxJava
generally has a steep learning curve, so it takes some time to get used to its concept.
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