Writing code on Android is hard. Writing high-quality code that involves concurrent and parallel tasks is even harder. Ensuring that this code will run without unforeseen race conditions is an order-of-magnitude harder. RxJava can help write code for such tasks.
In this course the novice developer will be introduced to a wide variety of tools that RxJava provides to enable them to produce robust and high-quality code for their asynchronous tasks by building a relatively simple application using advanced RxJava techniques to produce a high-quality product.
The starting sections will lead the developer through RxJava's initial setup in the Android environment. Later you will learn about RxJava 2.0 step-by-step by starting off with stock data processing and display. The developer will learn to choose appropriate Schedulers and to use the Retrofit library for remote requests. In the final sections, the viewer will also learn advanced topics such as adding integration to Twitter to process its streaming data by combining it with stock data.
About The Author
This led Tadas to a search for a library that would help him achieve a Promise-like functionality and interface. It didn't take him long to find ReactiveX and its family of implementations (including RxJava), which handles streams in a Reactive fashion. It didn't exactly offer the flow that Promise-like systems provide but, soon enough, he realized that it was even more powerful.
Since then, he has been using RxJava (and RxKotlin) for his daily Android programming. The quality of the code (the lack of bugs, readability, and maintainability) has improved ten-fold. Giving users of your application a fast, crash-free experience is a must these days when competition for user attention on app marketplaces is getting fiercer and fiercer.
Before we can start the development, we need to prepare dependencies
In this video, we will Create an initial UI where we will will be displaying changes of financial stocks over time and track stock updates.
New Java 8 features, such as lambdas and method references, are not available by default on the Android platform. So, this video shows you how to add some features of Java 8 using retrolambda.
In this video, we are going to take a look at observables and explore how they are related to disposables. Moving on, we will learn about schedulers.
The logging inside the steps of an observable is a very powerful tool when one wants to understand how they work.
In this video, you are going learn flowables and how to use back pressuring with flowables.
In this video, we will learn about three more types that RxJava provides.
In this video, you will learn how to set up necessary Retrofit dependencies and configure Retrofit interface objects to make simple HTTP GET requests.
The data that's returned by the API might not be readily usable as it is. Often, one needs to process the returned data to transform it into a more usable format.
It wouldn't be a proper financial stocks monitor, if it is unable to get updates automatically. To get updates automatically from the Yahoo Finance data, we will use a polling mechanism
Introduction of the regular updates of the stock quotes, generates lots of duplicate entries in the RecyclerView list. So, we will see lots of duplicate or rather irrelevant entries.
In this video, we will understand the differences between RxJava 1.0 and RxJava 2.0.
To make our lives easier, we will use another library that will help us connect old RxJava observables with the newer interfaces of RxJava 2.0.
There are a few types of schedulers and each of them is intended for a different type of work. Here, in this video , we will cover all of them
We will review the ways in which we can modify where the code gets executed
There are multiple ways to persist data locally for later consumption, but the most robust and convenient way on Android is the bundled SQLite database
It is important to gracefully inform the user about failures if they happen and, even more important, to not leave any loose exceptions so that they don't kill Android applications.
It's important to properly handle errors not only in the sense that they should be logged and shouldn't kill the app, but in the sense that the user should always be informed as to what happened.
In this video, we will explore a few ways of implementing a centralized logging solution so that it's easy to maintain and use.
We can now start creating a flow that will load locally saved StockUpdate entries from the SQLite database in cases when the quotes cannot be fetched from the internet.
Activities are the core components in Android to show the user interface. In most cases, all data processing, fetching, and any other action are tied to the activity.
If a proper lifecycle of the activity isn't maintained and one doesn't take care of cleaning up the resources, leaks will certainly happen
In this video, we will explore a few different ways to correctly destroy subscriptions
This video will show you that the creation of custom observables isn't complicated
Since we already know how to integrate any kind of Java code into the reactive flow, we are ready to start working with Twitter streams.
There is often a need to create and consume nested observables. In this video, we will see how to use .flatMap() in detail and how it works.
There will be a lot of cases where .map() is used, but we need to return the original value along with the new value.
It can so happen quite often that there is a need to execute two asynchronous tasks and wait for the result of both of them before the next step can be taken.
In this video, we will use .filter() to optimize certain parts of the application, and later, we will add notifications that will inform the user when a certain stock has dropped.
Extracting code into separate methods is a very simple yet super-effective technique to clarify the purpose of certain elements and make it easier to understand what is going on.
In the existing flow, we can see some spots where we can extract several code blocks in unison.
ObservableTransformer is a simple interface that defines a transformation on the observable object as a whole instead of the individual items that the observable produces.
We will see how we can move the extracted transformer to its own class that is to the persistence code, and we will explore a few additional examples for file-based caching and measuring the timing of the execution.
Quite often, there is a need to cache some kind of results between the runs of the application. The most convenient way to do this on Android is through a basic file-based caching.
Another useful example for the ObservableTransformer can be the tracking of the emission times of the items produced by the observable. In other words, how much times has passed since the start when this item was emitted.
One cool use case for transformations is to use them to print additional logging during the execution of the observable. This can be really useful when what's happening inside the observable flow is unclear.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.