Android Paging Library Step By Step Implementation Guide

Implementation of Paging Library from Scratch with Kotlin & REST API

Paging Library Architecture (Google CodeLab)
The Paging Library makes it easier for you to load data gradually and gracefully within your app's RecyclerView.
How Paging Library works (Medium)
  • Data comes from DataSource (REST API) on a background thread.
  • DataSource will update the PagedList value.
  • PagedList notifies its observers of the new list on the main thread.
  • PagedListAdapter will receive the new list.
  • PagedListAdapter will compute the changes using DiffUtil on background thread & returns the result on the main thread.
  • PagedListAdapter now calls OnBindViewHolder with updated data.

Conclusion :

At first steps to implement Paging Library might take longer than the traditional approach to handle pagination(Add scroll listener to find if user has reached to end & then calling API for next page).
But Paging Library adds abstract layers between UI logic and data logic which makes code more clean & testable. Also, Paging Library is highly configurable with its PagingList Configuration(page size, initial page size, placeholder),
Also, Paging Library efficiently handles fetching data from server & updating on UI with minimum changes.



Developer Android, Flutter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store