Preface What this book covers What you need for this book Who this book is for Conventions Reader feedback Customer support Downloading the example code Errata Piracy Questions Building your First “Hello World” RxJava Application Creating the application Dependencies Core dependencies UI dependencies Very first user interface Adding RecyclerView Stock data Value objects Using Retrolambda Setup Usage Updating the existing code Summary Understanding the Basics of RxJava Observables Hot and Cold Observables Disposables Schedulers Scheduling examples Investigating the flow of an Observable Flowable Dropping items Preserve latest item Buffering Completable, Single, and Maybe types Completable Single Maybe Summary Learning to use Retrofit by Fetching Financial Data Setting up Retrofit Making HTTP requests Service interface Service factory Creating service Transforming request data Parsing JSON Querying data Transforming JSON value objects Unwrapping nested objects Unwrapping lists Converting objects Displaying data on the UI Regular updates Handling multiple records on the UI Summary Integrating RxJava 1.0 with RxJava 2.0 Differences between the versions Dependencies and package name Functional interfaces Flowable Gluing different RxJava versions Setup Converting RxJava 1.0 Observables Converting to Flowables Summary Writing Data to SQLite and Schedulers Schedulers Types of Schedulers Single Trampoline NewThread IO Computation Executor Scheduler Android Scheduler Using Schedulers subscribeOn observeOn Rules of thumb Achieving parallelism Structuring code for parallelism Writing data with StorIO Setting up StorIO Configuring StorIO Preparing constants Creating write resolvers Creating StorIOSQLite interface Data persistence flow Summary Error Handling and SQLite Data Reading Exception handling in RxJava Using subscribe() Using onExceptionResumeNext() Using doOnError() Other error processing methods onErrorResumeNext() onErrorReturn onErrorReturnItem Showing errors in Android UI Empty State Screen Toast notification Centralized error logging Central handler Using RxJava plugins Reading SQLite data with StorIO Get resolver Reading cursor columns Converting data Creating the StockUpdate object Configuring Type Mapping Offline fallback for StockUpdate entries StorIO database query Creating the StorIO Observable The final onExceptionResumeNext() block Informing the user about the failure Missing delete resolver Summary Integrating RxJava with Activity Lifecycle Android Activity Lifecycle Lifecycle review Fragment lifecycles Setting up an activity Things to know about onCreate() calls Resource leaks Memory leaks Memory leak example Leaking with Observables Lost background tasks example Paying special attention to onCreate() Cleaning up Subscriptions Using Disposable Using CompositeDisposable Utilizing the RxLifecycle library Setting up the library Binding to Activity Lifecycle Binding to Activity without subclassing Binding to the Fragment lifecycle Binding to views Updating the data fetching flow Summary Writing Custom Observables How to create custom Observables Integrating with standard Java API Integrating with Emitter API Cleaning up Reading tweets for stocks reactively Setup Getting access to Twitter Custom Observable for Twitter Configuring Twitter Listening to status updates Emitting status updates into Observable Showing tweets in the UI Integrating Twitter status updates into the Flow Updating Value Objects StockUpdate adjustments StorIO adjustments Updating layouts Other improvements Summary Advanced Observable Flows Explained Unwrapping Observables Transforming values with Map FlatMap Observables More FlatMap variations SwitchMap Passing values Tuples JavaTuples Custom classes Updated flow Combining items Zip Combine latest Concatenating streams Concat Merge Filtering Cleaning stock adapter Advanced filtering with distinct calls Example of GroupBy Filtering tweets Summary Higher Level Abstractions Extracting code into methods Making conditions explicit Extracting consumers Using method references Extracting FlatMap Creating Factory Methods Financial stock quote Observable Tweet retrieval Observable Offline flow Observable Resulting flow Using Transformations Regular code extractions A Place where things start getting ugly Simplifying code with Transformations Extracting item persistence code Creating transformer classes File-based caching example Using Transformation to track execution time Using Transformation to debug Observables Summary Basics of Subjects and Preference Persistence Subjects PublishSubject Multiple sources BehaviorSubject ReplaySubject AsyncSubject Using subjects in the application Using RxPreferences Setup Examples with RxPreferences Subjects for Settings Connecting subjects to Settings Creating UI for Settings Creating Settings activity Preferences XML Options menu Updating flow Settings for financial stock updates Settings for monitored tweets Entire merge block Fixes for duplicate entries Summary Learning to Read Marble Diagrams Core elements of marble diagrams Elements of the diagram RxMarbles tool Examining operators Map FlatMap onExceptionResumeNext() GroupBy SubscribeOn and ObserveOn BehaviorSubject Summary