Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Pros & Cons: Event Bus and RxJava

I have been using Event Bus in my apps (i.e: greenrobot/EventBus). But I find some disadvantages in using Event Bus:

  • Chaining tasks execution is difficult
  • A lot of classes to represent events
  • Less clear code (well, it's still possible to trace, but not as clear)

I have been researching for new techniques to deal with this problem. And I read quite a bit about RxJava and wonder if it could be a solution.

So my questions about RxJava (based on what I have read recently):

  • Could RxJava observer be registered at any time? So not just when creating the Observable. With EventBus this is possible, I could subscribe at any time, not just when the Observable is created.
  • How do you handle two or more publishers publishing the same type of event (e.g: navigation event)?
  • Tightly coupling the publisher(s) and the subscriber, means that I have to explicitly specify the publisher(s) every time. So I have to worry not just with the type of events, but also the originators. With EventBus, I only need to worry about the type of events and not the originators.
like image 894
Pablo Espantoso Avatar asked May 10 '15 04:05

Pablo Espantoso


People also ask

What is better about Android than iPhone?

In addition to this, Android phones offer features like Always On Display, reverse wireless charging, fingerprint scanners, headphone jacks, split-screen multitasking, and more that are not available on the iPhone.

Is Android better than iPhone 2022?

Android phones consistently beat Apple to the punch with hardware advancements like better displays, cameras, and even features as basic as app widgets (iOS just got these in 2020).


1 Answers

1) Once you have an instance of an Observable, you can subscribe to it at any time and from any thread, even concurrently.

2) We usually merge the streams of multiple observables via Observable.merge() or use a serialized PublishSubject.

3) If you observe an Observable, there could be dozens of upstream operators and sources involved, but you'll get a sequential stream of values no matter what. You only need to get a hold onto an Observable representing some source of events and the observer doesn't need to know if the event was merged, filtered, made a roundtrip over the network and got delayed before arriving in your onNext() method. You can naturally implement or use some lookup service that will get you an Observable to reduce the coupling, but with RxJava, coupling is not usually an issue.

like image 95
akarnokd Avatar answered Oct 17 '22 01:10

akarnokd