What About RxJava?

In that sample, CitiesViewModel holds a LiveData of our PagedList, obtained from a LivePagedListBuilder.

If you prefer to use RxJava throughout your app — rather than perhaps a mix of LiveData and RxJava — you can use RxPagedListBuilder. This is in the android.arch.paging:rxjava2 artifact, which is newer than the rest of Paging and therefore may not necessarily have the same artifact versions.

You create an instance of RxPagedListBuilder using the same parameters as you would for a LivePagedListBuilder, such as the DataSource.Factory and the page size. You can then call:

Optionally, before the build...() method call, you can call setFetchScheduler() to provide the Scheduler to use for the data loading (e.g., Schedulers.single()) and/or setNotifyScheduler() to provide the Scheduler for delivering the results (e.g., AndroidSchedulers.mainThread()). The default notify scheduler is the main application thread, while the defualt fetch scheduler is one from a thread pool shared by many of the Architecture Components.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.