Book Image

RxJava Essentials

By : Ivan Morgillo
Book Image

RxJava Essentials

By: Ivan Morgillo

Overview of this book

<p>RxJava—Reactive Extensions for the JVM—is a library for composing asynchronous and event-based programs using Observable sequences for the Java VM, which will help you beat Android platform limitations to create astonishing Android apps.</p> <p>Starting with some quick background information on the Rx .NET library, this book quickly moves on to your first example. You will understand Observables and learn to filter, transform, or merge them in detail. Next, you will learn how to get rid of Threads, AsyncTasks, and Handlers with Schedulers to create a smooth user experience. Develop an easy, ready-to-go approach to REST API communications and enrich your skills by working with new challenging examples.</p> <p>By the end of the book, you will have explored the reactive programming world and will have created your first Android app without having to think about threading, networking, concurrency, and collection management.</p> <p>The images have been taken from&nbsp;<a href="http://reactivex.io/" target="_blank">http://reactivex.io/</a> which is licensed under a Create Commons 3.0 Attribution license (<a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">https://creativecommons.org/licenses/by/4.0/</a>)</p>
Table of Contents (15 chapters)

A few more examples


In this section, we are going to show a few examples based on RxJava's just(), repeat(), defer(), range(), interval(), and timer() methods.

just()

Let's assume we only have three separated AppInfo objects and we want to convert them into an Observable and populate our RecyclerView item:

List<AppInfo> apps = ApplicationsList.getInstance().getList();

AppInfo appOne = apps.get(0);

AppInfo appTwo = apps.get(10);

AppInfo appThree = apps.get(24);

loadApps(appOne, appTwo, appThree);

We can retrieve the list like we did in the previous example and extract only three elements. Then, we pass them to the loadApps() function:

private void loadApps(AppInfo appOne, AppInfo appTwo, AppInfo  appThree) {
    mRecyclerView.setVisibility(View.VISIBLE);

    Observable.just(appOne, appTwo, appThree)
            .subscribe(new Observer<AppInfo>() {
                @Override
                public void onCompleted() {
                    mSwipeRefreshLayout.setRefreshing(false)...