Home java Why do I need RxJava in Android?

Why do I need RxJava in Android?




I read a bunch of lessons and an article on RX in Habré. They all give examples with the problematic asyncTaskom which may not correctly process the request and return null or something else. Duck for this you need to handle the exception. And as for Retrofit requests, there is. Well, I don’t understand the usefulness of RXJava. Why is it needed at all?

Answer 1, authority 100%

RxJava is a library that implements a reactive approach to programming. You can read about reactive programming on the project site ReactiveX API .

ReactiveX is a combination of the best ideas from the Observer
pattern, the Iterator pattern, and functional programming

ReactiveX is a combination of the best ideas from the Observer design patterns and
Iterator and functional programming.

In simple terms, this is an approach in which you operate with events and data streams. Those. instead of “run and wait for the result” or “how it works
you need to run the callback and pass the result “you say” to it. Here’s a pipe, sit and look at it. As soon as data is poured into it, process it, and I’ll move on. “

This is mostly useful for building asynchronous applications and killing callback hell ‘a.

Roughly speaking, you have such entities as Observer (observer) and Observable (observable). The observer observes the observed and, when events (objects) fell from the observed, performs any actions with the stream of these events. In particular, no one prevents him from being “Observed” for another “observer” for example.

Imagine a long room with many boxes next to it (observed). Each box has a worker (observer) and, as soon as an object falls into the box, he takes it, does something with it, puts it in the next box in turn and takes the next object. The tsimus itself is that the different stages of processing are not tied to each other, i.e. all workers work at the same time – while the latter is processing object # 1, which has already passed almost the entire conveyor, the worker from the middle is working with object # 5, and the first worker is already standing smoking and waiting for new objects to fall from the hole in the wall.

Answer 2

Java, by its syntax, does not allow the use of reactive programming patterns. RxJava allows you to write programs in a reactive style

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions