PagingLiveData
public final class PagingLiveData
Summary
Public methods
cachedIn
public static final @NonNull LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> 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.
cachedIn
public static final @NonNull LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> 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 |
cachedIn
public static final @NonNull LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> 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 |
getLiveData
public static final @NonNull LiveData<@NonNull PagingData<@NonNull Value>> getLiveData(@NonNull Pager<@NonNull Key, @NonNull Value> receiver)
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.