Search⌘ K
AI Features

Reactive Everything: Replacing Callbacks

Explore how to replace traditional callback patterns with RxJava Observables in Android applications. Learn to create Observables that emit continuous data such as sensor and click events, manage subscriptions efficiently, and convert cold Observables to hot to share data streams across multiple observers.

So far, all the examples that we’ve looked at emit either one value, meaning that it can be modeled as a Single, or it can tell us if an operation succeeded or failed, meaning that it can be modeled as a Completable.

How might we convert areas in our app that receive continuous updates or events—for example, location updates, view click events, sensor events, and so on?

We’ll look at two ways to do this, first by using .create(), and then by using a new construct called Subject.

Using .create()

The .create() operator allows us to explicitly invoke any of the available methods of an Observer ...