Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between EventBus and RxJava? [duplicate]

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.

like image 815
HiddenDroid Avatar asked Feb 28 '16 17:02

HiddenDroid


People also ask

What is EventBus?

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.

What is RxBus?

RxBus - An event bus by ReactiveX/RxJava/ReactiveX/RxAndroid. This is an event bus designed to allowing your application to communicate efficiently.


1 Answers

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 BroadcastReceivers. 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.

like image 180
Vesko Avatar answered Oct 11 '22 11:10

Vesko