0Pricing
Android Academy · Lesson

RemoteMediator and Caching

Combine network and database paging.

Offline-First Paging

A plain network PagingSource works, but if the connection drops the list is empty. For a robust app you want the database as the single source of truth and the network filling it in the background.

That is exactly what RemoteMediator enables: page from the local database, and fetch more from the network when the database runs out.

The Architecture

With RemoteMediator the data flows in one direction:

  • The UI pages from a Room PagingSource
  • When Room nears its end, RemoteMediator fetches the next network page
  • The network result is written into Room
  • Room emits the new rows, and the UI updates

The user always sees cached data instantly, even offline.

// Network ---> RemoteMediator ---> Room (source of truth) ---> UI
// UI never reads the network directly

All lessons in this course

  1. Why Paging
  2. PagingSource and Pager
  3. Paging in Compose Lists
  4. RemoteMediator and Caching
← Back to Android Academy