Android 12 Developer Preview is here! Try it out, and give us your feedback!

PageKeyedDataSource

abstract class PageKeyedDataSource<Key : Any, Value : Any> : DataSource<Key, Value>
kotlin.Any
   ↳ androidx.paging.DataSource<Key, Value>
   ↳ androidx.paging.PageKeyedDataSource

Incremental data loader for page-keyed content, where requests return keys for next/previous pages.

Implement a DataSource using PageKeyedDataSource if you need to use data from page N - 1 to load page N. This is common, for example, in network APIs that include a next/previous link or key with each page load.

The InMemoryByPageRepository in the PagingWithNetworkSample shows how to implement a network PageKeyedDataSource using Retrofit, while handling swipe-to-refresh, network errors, and retry.

Summary

Nested classes
abstract

Callback for loadBefore and loadAfter to return data.

abstract

Callback for loadInitial to return data and, optionally, position/count information.

open

Holder object for inputs to loadInitial.

open

Holder object for inputs to loadBefore and loadAfter.

Public constructors

Incremental data loader for page-keyed content, where requests return keys for next/previous pages.

Public methods
abstract Unit

Append page with the key specified by LoadParams.key.

abstract Unit

Prepend page with the key specified by LoadParams.key.

abstract Unit

Load initial data.

PageKeyedDataSource<Key, ToValue>
map(function: Function<Value, ToValue>)

Applies the given function to each value emitted by the DataSource.

PageKeyedDataSource<Key, ToValue>
map(function: (Value) -> ToValue)

Applies the given function to each value emitted by the DataSource.

PageKeyedDataSource<Key, ToValue>
mapByPage(function: Function<List<Value>, List<ToValue>>)

Applies the given function to each value emitted by the DataSource.

PageKeyedDataSource<Key, ToValue>
mapByPage(function: (List<Value>) -> List<ToValue>)

Applies the given function to each value emitted by the DataSource.

Inherited functions
Inherited properties

Public constructors

<init>

PageKeyedDataSource()

Incremental data loader for page-keyed content, where requests return keys for next/previous pages.

Implement a DataSource using PageKeyedDataSource if you need to use data from page N - 1 to load page N. This is common, for example, in network APIs that include a next/previous link or key with each page load.

The InMemoryByPageRepository in the PagingWithNetworkSample shows how to implement a network PageKeyedDataSource using Retrofit, while handling swipe-to-refresh, network errors, and retry.

Parameters