Primary entry point into Paging; constructor for a reactive stream of PagingData. The same Pager instance should be reused within an instance of ViewModel. For example in your ViewModel:

// create a Pager instance and store to a variable
val pager = Pager(
...
)
.flow
.cachedIn(viewModelScope)

Each PagingData represents a snapshot of the backing paginated data. Updates to the backing dataset should be represented by a new instance of PagingData.

PagingSource.invalidate and calls to AsyncPagingDataDiffer.refresh or PagingDataAdapter.refresh will notify Pager that the backing dataset has been updated and a new PagingData / PagingSource pair will be generated to represent an updated snapshot.

PagingData can be transformed to alter data as it loads, and presented in a RecyclerView via AsyncPagingDataDiffer or PagingDataAdapter.

LiveData support is available as an extension property provided by the androidx.paging:paging-runtime artifact.

RxJava support is available as extension properties provided by the androidx.paging:paging-rxjava2 artifact.

Summary

Public constructors

<Key : Any, Value : Any> Pager(
    config: PagingConfig,
    initialKey: Key?,
    pagingSourceFactory: () -> PagingSource<Key, Value>
)
Cmn
@ExperimentalPagingApi
<Key : Any, Value : Any> Pager(
    config: PagingConfig,
    initialKey: Key?,
    remoteMediator: RemoteMediator<Key, Value>?,
    pagingSourceFactory: () -> PagingSource<Key, Value>
)
Cmn

Public properties

Flow<PagingData<Value>>

A cold Flow of PagingData, which emits new instances of PagingData once they become invalidated by PagingSource.invalidate or calls to AsyncPagingDataDiffer.refresh or PagingDataAdapter.refresh.

Cmn

Extension properties

LiveData<PagingData<Value>>
Pager<Key, Value>.liveData

A LiveData of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a LiveData.

android
Flowable<PagingData<Value>>
Pager<Key, Value>.flowable

A Flowable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a Flowable.

android
Observable<PagingData<Value>>
Pager<Key, Value>.observable

An Observable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as an Observable.

android
Flowable<PagingData<Value>>
Pager<Key, Value>.flowable

A Flowable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a Flowable.

android
Observable<PagingData<Value>>
Pager<Key, Value>.observable

An Observable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as an Observable.

android

Public constructors

Pager

<Key : Any, Value : Any> Pager(
    config: PagingConfig,
    initialKey: Key? = null,
    pagingSourceFactory: () -> PagingSource<Key, Value>
)

Pager

@ExperimentalPagingApi
<Key : Any, Value : Any> Pager(
    config: PagingConfig,
    initialKey: Key? = null,
    remoteMediator: RemoteMediator<Key, Value>?,
    pagingSourceFactory: () -> PagingSource<Key, Value>
)

Public properties

flow

val flowFlow<PagingData<Value>>

A cold Flow of PagingData, which emits new instances of PagingData once they become invalidated by PagingSource.invalidate or calls to AsyncPagingDataDiffer.refresh or PagingDataAdapter.refresh.

To consume this stream as a LiveData or in Rx, you may use the extensions available in the paging-runtime or paging-rxjava* artifacts.

NOTE: Instances of PagingData emitted by this Flow are not re-usable and cannot be submitted multiple times. This is especially relevant for transforms such as Flow.combine, which would replay the latest value downstream. To ensure you get a new instance of PagingData for each downstream observer, you should use the cachedIn operator which multicasts the Flow in a way that returns a new instance of PagingData with cached data pre-loaded.

Extension properties

liveData

val Pager<Key, Value>.liveDataLiveData<PagingData<Value>>

A LiveData of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a LiveData.

NOTE: Instances of PagingData emitted by this LiveData are not re-usable and cannot be submitted multiple times. This is especially relevant because LiveData will replays the latest value downstream. To ensure you get a new instance of PagingData for each downstream observer, you should use the cachedIn operator which multicasts the LiveData in a way that returns a new instance of PagingData with cached data pre-loaded.

flowable

val Pager<Key, Value>.flowableFlowable<PagingData<Value>>

A Flowable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a Flowable.

NOTE: Instances of PagingData emitted by this Flowable are not re-usable and cannot be submitted multiple times. This is especially relevant for transforms, which would replay the latest value downstream. To ensure you get a new instance of PagingData for each downstream observer, you should use the cachedIn operator which multicasts the Flowable in a way that returns a new instance of PagingData with cached data pre-loaded.

observable

val Pager<Key, Value>.observableObservable<PagingData<Value>>

An Observable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as an Observable.

NOTE: Instances of PagingData emitted by this Observable are not re-usable and cannot be submitted multiple times. This is especially relevant for transforms, which would replay the latest value downstream. To ensure you get a new instance of PagingData for each downstream observer, you should use the cachedIn operator which multicasts the Observable in a way that returns a new instance of PagingData with cached data pre-loaded.

flowable

val Pager<Key, Value>.flowableFlowable<PagingData<Value>>

A Flowable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as a Flowable.

NOTE: Instances of PagingData emitted by this Flowable are not re-usable and cannot be submitted multiple times. This is especially relevant for transforms, which would replay the latest value downstream. To ensure you get a new instance of PagingData for each downstream observer, you should use the cachedIn operator which multicasts the Flowable in a way that returns a new instance of PagingData with cached data pre-loaded.

observable

val Pager<Key, Value>.observableObservable<PagingData<Value>>

An Observable of PagingData, which mirrors the stream provided by Pager.flow, but exposes it as an Observable.

NOTE: Instances of PagingData emitted by this Observable are not re-usable and cannot be submitted multiple times. This is especially relevant for transforms, which would replay the latest value downstream. To ensure you get a new instance of PagingData for each downstream observer, you should use the cachedIn operator which multicasts the Observable in a way that returns a new instance of PagingData with cached data pre-loaded.