{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

PagingLiveData

{% setvar page_path %}androidx/paging/PagingLiveData.html{% endsetvar %} {% setvar can_switch %}1{% endsetvar %} {% include "reference/_kotlin_switcher2.md" %}

class PagingLiveData


Summary

Public functions

<ERROR CLASS>

Operator which caches a LiveData of PagingData within the scope of a Lifecycle.

<ERROR CLASS>

Operator which caches a LiveData of PagingData within the scope of a ViewModel.

<ERROR CLASS>

Operator which caches a LiveData of PagingData within a CoroutineScope.

Public functions

cachedIn

fun <T : Any> <ERROR CLASS><PagingData<T>>.cachedIn(lifecycle: <ERROR CLASS>): <ERROR CLASS>

Operator which caches a LiveData of PagingData within the scope of a Lifecycle.

cachedIn multicasts pages loaded and transformed by a PagingData, allowing multiple observers on the same instance of PagingData to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling cachedIn is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of PagingData emitted by Pager or any of its transformed derivatives, as reloading data from scratch on the same generation of PagingData is an unsupported operation.

Parameters
lifecycle: <ERROR CLASS>

The Lifecycle where the page cache will be kept alive.

cachedIn

fun <T : Any> <ERROR CLASS><PagingData<T>>.cachedIn(viewModel: <ERROR CLASS>): <ERROR CLASS>

Operator which caches a LiveData of PagingData within the scope of a ViewModel.

cachedIn multicasts pages loaded and transformed by a PagingData, allowing multiple observers on the same instance of PagingData to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling cachedIn is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of PagingData emitted by Pager or any of its transformed derivatives, as reloading data from scratch on the same generation of PagingData is an unsupported operation.

Parameters
viewModel: <ERROR CLASS>

The ViewModel whose viewModelScope will dictate how long the page cache will be kept alive.

cachedIn

fun <T : Any> <ERROR CLASS><PagingData<T>>.cachedIn(scope: CoroutineScope): <ERROR CLASS>

Operator which caches a LiveData of PagingData within a CoroutineScope.

cachedIn multicasts pages loaded and transformed by a PagingData, allowing multiple observers on the same instance of PagingData to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling cachedIn is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of PagingData emitted by Pager or any of its transformed derivatives, as reloading data from scratch on the same generation of PagingData is an unsupported operation.

Parameters
scope: CoroutineScope

The CoroutineScope where the page cache will be kept alive. Typically this would be a managed scope such as ViewModel.viewModelScope, which automatically cancels after the PagingData stream is no longer needed. Otherwise, the provided CoroutineScope must be manually cancelled to avoid memory leaks.