Android Paging 3.0

Adapting Android: Migrating from Paging 2.0 to Paging 3.0

Daniel Tan
2 min readJun 12, 2020

As part of the Android 11 beta release, Google has also updated the Jetpack Paging library to 3.0, which according to the blog post, is a major update.

..a major update to Paging 3, rewritten Kotlin-first with full support for coroutines!

What’s Changed?

  1. A complete rewrite from 2.0 using Kotlin with coroutines.
  2. Built-in separator, header and footer support.
  3. Built-in retry and refresh mechanism.

Architecture

Despite being a complete rewrite, the architecture remains the same as 2.0.

Figure 1: Paging 3.0 architecture (source)

As comparison, I drafted the common MVVM design pattern that’s been in use for a long while.

Figure 2: Common MVVM design pattern in Android

To map paging 2.0 against Figure 2, we get the following:

  • Source -> DataSource
  • Pager -> LivePagedListBuilder
  • Data Stream -> LiveData<PagedList<T>>
  • Adapter -> PagedListAdapter

Migration

With the same architecture, migration is almost a drop-in replacement of a few classes. Let’s visualize the migration as below.

Figure 3: Migration from paging 2.0 to 3.0

Not all classes are required to changed, here’s to summarize:

# Not changed (or required)

  • DiffUtil.ItemCallback can be reused as it is.
  • DataSource.Factory is no longer required.

# Changed

  • Adapter, Config and Pager are all so similar that its almost a straight 1-to-1 mapping.
  • ItemKeyedDataSource, PageKeyedDataSource and PositionalDataSource are all merged into a single PagingSource .

Note: PagingSource is backward compatible with LivePagedListBuilder and RxPagedListBuilder if you are using any of this.

Conclusion

  • Migration from paging 2.0 to 3.0 seems easy enough.
  • Migrating DataSource to PagingSource might required more efforts.
  • Not sure if the added features (header, footer, etc) is going to be helpful at this point.

Here is a demo project that implements both paging 2.0 and paging 3.0. You can find a lot of similarities in between the 2 implementations.

--

--