-3

this is more an architectural question or also maybe a question of point of view.

Many Android libs have an reactive approach in there APIs. e.g. Volley , Volley have a nice JsonObjectRequest to put it into a RequestQueue and in the callback onResponse you can handle the response.

Or in Picasso you have also an async call to just load the picture in a given ImageView.

In the new Persistent Tool ObjectBox for Android you have also an reactive approach to set and query data from the database.

So my question is, where are the great needing of RXJava in Android? In which UseCases is RXJava essential?

deadpoint
  • 433
  • 3
  • 17
  • Please check RxAndroid Uses. reactive pattern and scheduling. check https://stackoverflow.com/questions/21890338/when-should-one-use-rxjava-observable-and-when-simple-callback-on-android – Shubham AgaRwal Sep 12 '17 at 16:11

1 Answers1

1

Reactive is not the same as "observer pattern". Call backs are not the same as reactive. Custom-fitted call back interfaces are much more specific and not as easy to generalize as the reactive implementation of RxJava.

  1. RxJava follows the observable contract, meaning that its behavior is consistent within itself, and that behavior is readily generalizable.
  2. RxJava uses a basic set of operators, with Java generics, to provide a very rich customization portfolio. An Observable<CustomJsonObject> is known to behave in the same way as an Observable<Long>.
  3. Given (1) and (2), you will find that you can compose reactive operators to get customized behavior. Hence, customJsonObjectObservable.distinctUntilChanged() will behave in the same way that longObservable.distinctUntilChanged(). You don't need to create a custom class that stores the previous item for comparison, as the operator takes care of that for you.
  4. Introducing the passage of time or multiple threads is done using operators, and these aspects are also composable. The interval() operator provides periodic updates, the buffer() operator collects data that arrives within a period, and the timeout() operator monitors data and announces when it is not present in a time period.

Point (4) is probably the biggest win for RxJava. Reasoning about the passage of time, especially in the presence of multiple threads of control, is very hard. RxJava brings those difficult areas under control. Hard problems are not quite so hard to solve, and very hard problems can often be decomposed into areas with easier solutions.

Volley does not address the hard issues. It provides asynchronous responses, and addresses only a fraction of item (1) above. It does not address (2), (3) or (4).

Bob Dalgleish
  • 8,167
  • 4
  • 32
  • 42