O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Subjects

A Subject is a consumer and an Observable at the same time. It means that it can listen for values from other Observables (subscribe to Observable), and it can produce values for other subscribers. So, for example, the following code is valid with a Subject:

Subject<String> subject = ...;subject.subscribe(v -> log(v));Observable.just("1")        .subscribe(subject);

We can see that, on the second line, we were able to subscribe to the subject successfully, and it means that it acts as Observable here. On the third line, we made the subject listen to the changes that this other Observable will produce.

As we will see later, this can come in extremely handy when we want to connect individual Observables without creating direct dependencies ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required