Chapter 5. Advanced RxJava
In this chapter
- Creating your own observables
- Threading with RxJava
- Understanding subjects and what they’re good for
- Cleaning up subscriptions
You’ve seen observables in many forms, but in this chapter you’ll learn how to create your own. Seeing the internals can help you to understand how the system works, even if usually this isn’t necessary for the applications you’ll build.
The second important topic we’ll discuss is threading. You’ve already switched the execution back to the main thread in order to update the UI, but you never quite saw how it works. This time, you’ll see what RxJava provides to freely manipulate the thread of execution, starting from the internal logic of the observable itself.
We’ll also cover a new matter called subjects. A subject is a fusion of an observable and a subscriber, combining the best and the worst of both. You need to know how to use subjects, though it’s perhaps even more necessary to understand why most of the time you shouldn’t use them.
The preceding image is a simple abstract to help you get an idea of what I’m talking about, and we’ll get into the details later in the chapter. You’ll also see the valid use cases for subjects.