RxJava in Action
Discover how to implement RxJava by following a step-by-step example that filters, transforms, and limits data streams on background and UI threads. Learn how each operator contributes to building reactive pipelines that handle asynchronous data efficiently and update the user interface.
We'll cover the following...
Sample RxJava code
Let’s take a look at some RxJava in action:
The above code will get the top 5 sub-$90,000 electric cars and then update the UI with that data.
There’s a lot going on here, so let’s see how it does this line-by-line:
-
Line 1: It all starts with our
Observable, the source of our data. TheObservablewaits for an observer to subscribe to it, at which point it does some work and pushes data to itsObserver. We intentionally abstract away the creation of thecarsObservablehere, and we’ll cover how to create anObservablein the next chapter. For now, let’s assume the work that theObservablewill be doing is querying a REST API to get an ordered list of the top-selling cars. ...