PagingLiveData

public final class PagingLiveData


Summary

Public fields

final @NonNull LiveData<@NonNull PagingData<@NonNull Value>>

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

Public methods

static final @NonNull LiveData<@NonNull PagingData<@NonNull T>>
<T extends Object> PagingLiveData.cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull Lifecycle lifecycle
)

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

static final @NonNull LiveData<@NonNull PagingData<@NonNull T>>
<T extends Object> PagingLiveData.cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull ViewModel viewModel
)

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

static final @NonNull LiveData<@NonNull PagingData<@NonNull T>>
<T extends Object> PagingLiveData.cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull CoroutineScope scope
)

Operator which caches a LiveData of PagingData within a CoroutineScope.

Public fields

liveData

@NonNull
public final @NonNull LiveData<@NonNull PagingData<@NonNull Value>> liveData

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

Public methods

PagingLiveData.cachedIn

@NonNull
public static final LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> PagingLiveData.cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull Lifecycle lifecycle
)

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
@NonNull Lifecycle lifecycle

The Lifecycle where the page cache will be kept alive.

PagingLiveData.cachedIn

@NonNull
public static final LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> PagingLiveData.cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull ViewModel viewModel
)

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
@NonNull ViewModel viewModel

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

PagingLiveData.cachedIn

@NonNull
public static final LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> PagingLiveData.cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull CoroutineScope scope
)

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
@NonNull CoroutineScope scope

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.