Android & Kotlin

Reactive Programming with Kotlin

The book that teaches you to use RxJava, RxAndroid and RxKotlin to create complex reactive applications on Android and exercise full control over the library to leverage the full power of reactive programming in your apps. By Florent Pillet, Junior Bontognali, Scott Gardner, Alex Sullivan & Marin Todorov.

Read for Free with the Personal Plan* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99* *Includes access to all of our online reading features.
Leave a rating/review
Download materials
Buy paperback—Amazon Comments
Save for later
Share

Who is this for?

This book is for Android developers who already feel comfortable with the Android SDK and Kotlin, and want to dive deep into development with RxJava, RxKotlin, and RxAndroid.

Covered concepts

  • Getting Started
  • Event Management
  • Being Selective
  • UI Development
  • Intermediate Topics: reactive networking, error handling and schedulers
  • Advanced Topics: app architecture, repositories and integrating RxJava with Android Jetpack

Learn Reactive Programming in Kotlin with RxJava!

Not only will you learn how to use RxJava to create complex reactive applications on Android, you’ll also see how to solve common application design issues by using RxJava, RxAndroid and RxKotlin. Finally, you’ll discover how to exercise full control over the library...

more

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.

Section I: Getting Started with RxJava

In this part of the book, you’re going to learn about the basics of RxJava. You are going to have a look at what kinds of asynchronous programming problems RxJava addresses, and what kind of solutions it offers.

Further, you will learn about the few basic classes that allow you to create and observe event sequences, which are the foundation of the Rx framework.

You are going to start slow by learning about the basics and a little bit of theory. Please don’t skip these chapters! This will allow you to make good progress in the following sections when things get more complex.

1
Toggle description
Learn about the reactive programming paradigm and what RxJava can bring to your app.
2
Toggle description
Now that you’re ready to use RxJava and have learned some of the basic concepts, it’s time to play around with observables.
3
Toggle description
In this chapter, you’re going to learn about the different types of subjects in RxJava, see how to work with each one and why you might choose one over another based on some common use cases.
4
Toggle description
In this chapter, you’ll use RxJava and your new observable super-powers to create an app that lets users to create nice photo collages — the reactive way.

Section II: Operators & Best Practices

Operators are the building blocks of Rx, which you can use to transform, process, and react to events emitted by Observables.

Just as you can combine simple arithmetic operators like +, -, and / to create complex math expressions, you can chain and compose together Rx’s simple operators to express complex app logic.

In this chapter, you are going to:

  • Start by looking into filtering operators, which allow you to process some events but ignore others.
  • Move on to transforming operators, which allow you to create and express complex data transformations. You can for example start with a button event, transform that into some kind of input, process that and return some output to show in the app UI.
  • Look into combining operators, which allow for powerful composition of most other operators.
  • Explore operators that allow you to do time based processing: delaying events, grouping events over periods of time, and more. Work though all the chapters, and by the end of this section you’ll be able to write simple RxJava apps!
Toggle description
This chapter will teach you about RxJava’s filtering operators that you can use to apply conditional constraints to “next” events, so that the subscriber only receives the elements it wants to deal with.
Toggle description
In the previous chapter, you began your introduction to the functional side of RxJava. In this chapter, you’re going to try using the filtering operators in a real-life app.
Toggle description
In this chapter, you’re going to learn about one of the most important categories of operators in RxJava: transforming operators.
In this chapter, you’ll take an existing app and add RxJava transforming operators as you learn more about map and flatMap, and in which situations you should use them in your code.
Toggle description
This chapter will show you several different ways to assemble sequences, and how to combine the data within each sequence.
Toggle description
You'll get an opportunity to try some of the most powerful RxJava operators. You'll learn to solve problems similar to those you'll face in your own applications.
Toggle description
Managing the time dimension of your sequences is important. To learn about time-based operators, you'll practice with an animated app that visually demonstrates how data flows over time.

Section III: Intermediate RxJava

Once you start writing complete apps with RxJava, you will also need to take care of more intermediate topics than simply observing for events and processing them with Rx.

In a full production-quality app, you will need to build an error handling strategy, do more advanced multi-threading processing, create a solid test suite, and more.

In this part of the book, you will work through five challenging chapters, which will lift your Rx status from a rookie level to a battle-tested warrior.

Toggle description
Even the best RxJava developers can’t avoid encountering errors. You’ll learn how to deal with errors, how to manage error recovery through retries, or just surrender yourself to the universe and letting the errors go.
Toggle description
This chapter will cover the beauty behind schedulers, where you’ll learn why the Rx abstraction is so powerful and why working with asynchronous programming is far less less painful than using locks or queues.
Toggle description
Observables are very powerful, but what happens if a subscriber can't keep up with the next events? You'll see how to handle this situation using Flowables.
Toggle description
Testing your code is at the heart of writing good software— RxJava comes with lots of nifty tricks for testing everything under the sun.
Beyond using the elements made available directly by RxJava, you can also create RxJava wrappers around existing non-Rx frameworks. You'll learn how to create and incorporate such wrappers into your reactive application.

Section IV: RxJava Community Cookbook

RxJava’s popularity keeps growing every day. Thanks to the friendly and creative community that formed around this library, a lot of community-driven Rx projects are being released on GitHub.

The advantage of the community-built libraries that use RxJava is that unlike the main repository, which needs to follow the Rx standard, these libraries can afford to experiment and explore different approaches, provide non multi-platform specializations, and more.

In this section you are going to look into just a few of the many community open source projects. The section contains four short cookbook-style chapters that look briefly into four community projects that help you with binding Android Views, talking to your server with Retrofit, persisting preferences data, and handling user permissions.

Toggle description
You'll learn how the extremely handy library RxBinding takes care of making reactive bindings for the Android View classes, and see how to use RxBinding in an app.
Toggle description
In earlier chapters, you've used Retrofit to add networking to your reactive apps. In this chapter, explore exactly how Retrofit interfaces with the Rx world and see how you can take advantage of all that it offers.
Toggle description
The RxPreferences library provides a reactive wrapper around SharedPreferences. In this chapter, you'll learn how the library works and how you can use it to effectively stream preference changes.
Toggle description
There's a fantastic library called RxPermissions that you'll use in this chapter to help alleviate the pain points of asking the user for permissions at runtime, giving you a reactive flow when requesting permissions.

Section V: Putting It All Together

The “easy” part of the book is over. If you made it this far and are looking to learn even more in order to start creating production apps with RxJava, this section is for you.

The two chapters in this section are going to help you learn how to build real-life applications with RxJava.

The first chapter will cover integrating RxJava with the components of Android Jetpack, in particular, the Room database library and the Paging library. The chapter will build off of knowledge you’ve gained earlier in the book working with the ViewModel and LiveData components of Jetpack.

The second chapter, and the last one in this book, is going to show you how to setup a reactive application architecture and how to convert callbacks to Rx Observables.

Once you finish working through this section, you will be one of the top RxJava developers out there. There is, of course, more to know about Rx but at this point you will be able to figure out things further on your own.

Also, don’t forget to give back to the community! It would not have been possible for us to put this book together without all the amazing Rx folks sharing their knowledge, code, and good vibes.

Toggle description
Android Jetpack is a suite of libraries provided by the Android team to make developing Android apps a breeze. You've already seen ViewModel and LiveData used with RxJava. In this chapter, you'll explore using the Room and Paging Library components from Jetpack in a reactive app.
Toggle description
To conclude this book, you’ll architect and code a small RxJava application. The goal is not to use Rx “at all costs”, but rather to make design decisions that lead to a tidy architecture with stable, predictable and modular behavior. The application is simple by design, to clearly present ideas you can use to architect your own applications.