blob: 0ec9e9ff237e855da8910ee91c9bba291c33897c [file] [log] [blame]
<html devsite="true">
<head>
<title>RemoteMediator</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div id="metadata-info-block"></div>
<h1>RemoteMediator</h1>
<p>
<pre>@<a href="/reference/androidx/paging/ExperimentalPagingApi.html">ExperimentalPagingApi</a><br>public abstract class <a href="/reference/androidx/paging/RemoteMediator.html">RemoteMediator</a>&lt;Key&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;Value&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt;</pre>
</p>
<div class="devsite-table-wrapper"><devsite-expandable><span class="expand-control jd-sumtable-subclasses">Known direct subclasses
<div class="showalways" id="subclasses-direct"><a href="/reference/androidx/paging/ListenableFutureRemoteMediator.html">ListenableFutureRemoteMediator</a>, <a href="/reference/androidx/paging/rxjava2/RxRemoteMediator.html">RxRemoteMediator</a>, <a href="/reference/androidx/paging/rxjava3/RxRemoteMediator.html">RxRemoteMediator</a></div>
</span>
<div id="subclasses-direct-summary">
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<tbody class="list">
<tr>
<td width="40%"><code><a href="/reference/androidx/paging/ListenableFutureRemoteMediator.html">ListenableFutureRemoteMediator</a></code></td>
<td>
<p><code><a href="https://guava.dev/releases/18.0/api/docs/package-list/com/google/common/util/concurrent/ListenableFuture.html">ListenableFuture</a></code>-based compatibility wrapper around <code><a href="/reference/androidx/paging/RemoteMediator.html">RemoteMediator</a></code>'s suspending APIs.</p>
</td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/androidx/paging/rxjava2/RxRemoteMediator.html">RxRemoteMediator</a></code></td>
<td>
<p>RxJava2 compatibility wrapper around <code><a href="/reference/androidx/paging/RemoteMediator.html">RemoteMediator</a></code>'s suspending APIs.</p>
</td>
</tr>
<tr>
<td width="40%"><code><a href="/reference/androidx/paging/rxjava3/RxRemoteMediator.html">RxRemoteMediator</a></code></td>
<td>
<p>RxJava3 compatibility wrapper around <code><a href="/reference/androidx/paging/RemoteMediator.html">RemoteMediator</a></code>'s suspending APIs.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</devsite-expandable> </div>
<hr>
<p>Defines a set of callbacks used to incrementally load data from a remote source into a local source wrapped by a <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>, e.g., loading data from network into a local db cache.</p>
<p>A <code><a href="/reference/androidx/paging/RemoteMediator.html">RemoteMediator</a></code> is registered by passing it to <code><a href="/reference/androidx/paging/Pager.html">Pager</a></code>'s constructor.</p>
<p><code><a href="/reference/androidx/paging/RemoteMediator.html">RemoteMediator</a></code> allows hooking into the following events:</p>
<ul>
<li>
<p>Stream initialization</p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> signal driven from UI</p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> returns a <code><a href="/reference/androidx/paging/PagingSource.LoadResult.html">LoadResult</a></code> which signals a boundary condition, i.e., the most recent <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html">LoadResult.Page</a></code> in the <code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> or <code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> direction has <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html#prevKey()">LoadResult.Page.prevKey</a></code> or <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html#nextKey()">LoadResult.Page.nextKey</a></code> set to <code>null</code> respectively.</p>
</li>
</ul>
<pre class="prettyprint">
import androidx.room.withTransaction
/**
* Sample RemoteMediator for a DB + Network based PagingData stream, which triggers network
* requests to fetch additional items when a user scrolls to the end of the list of items stored
* in DB.
*
* This sample loads a list of [User] items from an item-keyed Retrofit paginated source. This
* source is &quot;item-keyed&quot; because we're loading the next page using information from the items
* themselves (the ID param) as a key to fetch more data.
*/
@OptIn(ExperimentalPagingApi::class)
class ExampleRemoteMediator(
private val query: String,
private val database: RoomDb,
private val networkService: ExampleBackendService
) : RemoteMediator&lt;Int, User&gt;() {
val userDao = database.userDao()
override suspend fun initialize(): InitializeAction {
val cacheTimeout = TimeUnit.HOURS.convert(1, TimeUnit.MILLISECONDS)
return if (System.currentTimeMillis() - userDao.lastUpdated() &gt;= cacheTimeout) {
// Cached data is up-to-date, so there is no need to re-fetch from network.
InitializeAction.SKIP_INITIAL_REFRESH
} else {
// Need to refresh cached data from network; returning LAUNCH_INITIAL_REFRESH here
// will also block RemoteMediator's APPEND and PREPEND from running until REFRESH
// succeeds.
InitializeAction.LAUNCH_INITIAL_REFRESH
}
}
override suspend fun load(
loadType: LoadType,
state: PagingState&lt;Int, User&gt;
): MediatorResult {
return try {
// The network load method takes an optional `after=&lt;user.id&gt;` parameter. For every
// page after the first, we pass the last user ID to let it continue from where it
// left off. For REFRESH, pass `null` to load the first page.
val loadKey = when (loadType) {
LoadType.REFRESH -&gt; null
// In this example, we never need to prepend, since REFRESH will always load the
// first page in the list. Immediately return, reporting end of pagination.
LoadType.PREPEND -&gt; return MediatorResult.Success(endOfPaginationReached = true)
LoadType.APPEND -&gt; {
val lastItem = state.lastItemOrNull()
// We must explicitly check if the last item is `null` when appending,
// since passing `null` to networkService is only valid for initial load.
// If lastItem is `null` it means no items were loaded after the initial
// REFRESH and there are no more items to load.
if (lastItem == null) {
return MediatorResult.Success(endOfPaginationReached = true)
}
lastItem.id
}
}
// Suspending network load via Retrofit. This doesn't need to be wrapped in a
// withContext(Dispatcher.IO) { ... } block since Retrofit's Coroutine CallAdapter
// dispatches on a worker thread.
val response = networkService.searchUsers(query = query, after = loadKey)
database.withTransaction {
if (loadType == LoadType.REFRESH) {
userDao.deleteByQuery(query)
}
// Insert new users into database, which invalidates the current
// PagingData, allowing Paging to present the updates in the DB.
userDao.insertAll(response.users)
}
MediatorResult.Success(endOfPaginationReached = response.nextKey == null)
} catch (e: IOException) {
MediatorResult.Error(e)
} catch (e: HttpException) {
MediatorResult.Error(e)
}
}
}</pre>
<pre class="prettyprint">
import androidx.paging.samples.shared.RemoteKey
import androidx.room.withTransaction
/**
* Sample RemoteMediator for a DB + Network based PagingData stream, which triggers network
* requests to fetch additional items when a user scrolls to the end of the list of items stored
* in DB.
*
* This sample loads a list of [User] via Retrofit from a page-keyed network service using
* [String] tokens to load pages (each response has a next/previous token), and inserts them
* into database.
*/
@OptIn(ExperimentalPagingApi::class)
class ExampleRemoteMediator(
private val query: String,
private val database: RoomDb,
private val networkService: ExampleBackendService
) : RemoteMediator&lt;Int, User&gt;() {
val userDao = database.userDao()
val remoteKeyDao = database.remoteKeyDao()
override suspend fun initialize(): InitializeAction {
val cacheTimeout = TimeUnit.HOURS.convert(1, TimeUnit.MILLISECONDS)
return if (System.currentTimeMillis() - userDao.lastUpdated() &gt;= cacheTimeout) {
// Cached data is up-to-date, so there is no need to re-fetch from network.
InitializeAction.SKIP_INITIAL_REFRESH
} else {
// Need to refresh cached data from network; returning LAUNCH_INITIAL_REFRESH here
// will also block RemoteMediator's APPEND and PREPEND from running until REFRESH
// succeeds.
InitializeAction.LAUNCH_INITIAL_REFRESH
}
}
override suspend fun load(
loadType: LoadType,
state: PagingState&lt;Int, User&gt;
): MediatorResult {
return try {
// The network load method takes an optional [String] parameter. For every page
// after the first, we pass the [String] token returned from the previous page to
// let it continue from where it left off. For REFRESH, pass `null` to load the
// first page.
val loadKey = when (loadType) {
LoadType.REFRESH -&gt; null
// In this example, we never need to prepend, since REFRESH will always load the
// first page in the list. Immediately return, reporting end of pagination.
LoadType.PREPEND -&gt; return MediatorResult.Success(endOfPaginationReached = true)
// Query remoteKeyDao for the next RemoteKey.
LoadType.APPEND -&gt; {
val remoteKey = database.withTransaction {
remoteKeyDao.remoteKeyByQuery(query)
}
// We must explicitly check if the page key is `null` when appending,
// since `null` is only valid for initial load. If we receive `null`
// for APPEND, that means we have reached the end of pagination and
// there are no more items to load.
if (remoteKey.nextKey == null) {
return MediatorResult.Success(endOfPaginationReached = true)
}
remoteKey.nextKey
}
}
// Suspending network load via Retrofit. This doesn't need to be wrapped in a
// withContext(Dispatcher.IO) { ... } block since Retrofit's Coroutine CallAdapter
// dispatches on a worker thread.
val response = networkService.searchUsers(query, loadKey)
// Store loaded data, and next key in transaction, so that they're always consistent
database.withTransaction {
if (loadType == LoadType.REFRESH) {
remoteKeyDao.deleteByQuery(query)
userDao.deleteByQuery(query)
}
// Update RemoteKey for this query.
remoteKeyDao.insertOrReplace(RemoteKey(query, response.nextKey))
// Insert new users into database, which invalidates the current
// PagingData, allowing Paging to present the updates in the DB.
userDao.insertAll(response.users)
}
MediatorResult.Success(endOfPaginationReached = response.nextKey == null)
} catch (e: IOException) {
MediatorResult.Error(e)
} catch (e: HttpException) {
MediatorResult.Error(e)
}
}
}</pre>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Nested types</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code>public enum <a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html">RemoteMediator.InitializeAction</a> extends <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-enum/index.html">Enum</a></code></div>
<p>Return type of <code><a href="/reference/androidx/paging/RemoteMediator.html#initialize()">initialize</a></code>, which signals the action to take after <code><a href="/reference/androidx/paging/RemoteMediator.html#initialize()">initialize</a></code> completes.</p>
</td>
</tr>
<tr>
<td>
<div><code>public class <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.html">RemoteMediator.MediatorResult</a></code></div>
<p>Return type of <code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a></code>, which determines <code><a href="/reference/androidx/paging/LoadState.html">LoadState</a></code>.</p>
</td>
</tr>
<tr>
<td>
<div><code>public final class <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.Error.html">RemoteMediator.MediatorResult.Error</a> extends <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.html">RemoteMediator.MediatorResult</a></code></div>
<p>Recoverable error that can be retried, sets the <code><a href="/reference/androidx/paging/LoadState.html">LoadState</a></code> to <code><a href="/reference/androidx/paging/LoadState.Error.html">LoadState.Error</a></code>.</p>
</td>
</tr>
<tr>
<td>
<div><code>public final class <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.Success.html">RemoteMediator.MediatorResult.Success</a> extends <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.html">RemoteMediator.MediatorResult</a></code></div>
<p>Success signaling that <code><a href="/reference/androidx/paging/LoadState.html">LoadState</a></code> should be set to <code><a href="/reference/androidx/paging/LoadState.NotLoading.html">LoadState.NotLoading</a></code> if <code><a href="/reference/androidx/paging/RemoteMediator.MediatorResult.Success.html#endOfPaginationReached()">endOfPaginationReached</a></code> is <code>true</code>, otherwise <code><a href="/reference/androidx/paging/LoadState.html">LoadState</a></code> is kept at <code><a href="/reference/androidx/paging/LoadState.Loading.html">LoadState.Loading</a></code> to await invalidation.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code>&lt;Key&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;Value&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/RemoteMediator.html#RemoteMediator()">RemoteMediator</a>()</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html">RemoteMediator.InitializeAction</a></code></td>
<td>
<div><code><a href="/reference/androidx/paging/RemoteMediator.html#initialize()">initialize</a>()</code></div>
<p>Callback fired during initialization of a <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> stream, before initial load.</p>
</td>
</tr>
<tr>
<td width="40%"><code>abstract @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.html">RemoteMediator.MediatorResult</a></code></td>
<td>
<div><code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/LoadType.html">LoadType</a>&nbsp;loadType,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingState.html">PagingState</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;&nbsp;state<br>)</code></div>
<p>Callback triggered when Paging needs to request more data from a remote source due to any of the following events:</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public constructors</h2>
<div class="api-item"><a name="RemoteMediator--"></a><a name="remotemediator"></a>
<h3 class="api-name" id="RemoteMediator()">RemoteMediator</h3>
<pre class="api-signature no-pretty-print">public&nbsp;&lt;Key&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>,&nbsp;Value&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/RemoteMediator.html#RemoteMediator()">RemoteMediator</a>()</pre>
</div>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="initialize--"></a><a name="initialize"></a>
<h3 class="api-name" id="initialize()">initialize</h3>
<pre class="api-signature no-pretty-print">public&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html">RemoteMediator.InitializeAction</a>&nbsp;<a href="/reference/androidx/paging/RemoteMediator.html#initialize()">initialize</a>()</pre>
<p>Callback fired during initialization of a <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> stream, before initial load.</p>
<p>This function runs to completion before any loading is performed.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html">RemoteMediator.InitializeAction</a></code></td>
<td>
<p><code><a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html">InitializeAction</a></code> used to control whether <code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a></code> with load type <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> will be immediately dispatched when the first <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> is submitted:</p>
<ul>
<li>
<p><code><a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html#LAUNCH_INITIAL_REFRESH">LAUNCH_INITIAL_REFRESH</a></code> to immediately dispatch <code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a></code> asynchronously with load type <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code>, to update paginated content when the stream is initialized. Note: This also prevents <code><a href="/reference/androidx/paging/RemoteMediator.html">RemoteMediator</a></code> from triggering <code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> or <code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> until <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> succeeds.</p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html#SKIP_INITIAL_REFRESH">SKIP_INITIAL_REFRESH</a></code> to wait for a refresh request from the UI before dispatching <code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a></code> asynchronously with load type <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code>.</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="load(androidx.paging.LoadType, androidx.paging.PagingState)"></a><a name="load-androidx.paging.LoadType-androidx.paging.PagingState-"></a><a name="load"></a>
<h3 class="api-name" id="load(androidx.paging.LoadType,androidx.paging.PagingState)">load</h3>
<pre class="api-signature no-pretty-print">public&nbsp;abstract&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.html">RemoteMediator.MediatorResult</a>&nbsp;<a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/LoadType.html">LoadType</a>&nbsp;loadType,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingState.html">PagingState</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;&nbsp;state<br>)</pre>
<p>Callback triggered when Paging needs to request more data from a remote source due to any of the following events:</p>
<ul>
<li>
<p>Stream initialization if <code><a href="/reference/androidx/paging/RemoteMediator.html#initialize()">initialize</a></code> returns <code><a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html#LAUNCH_INITIAL_REFRESH">LAUNCH_INITIAL_REFRESH</a></code></p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> signal driven from UI</p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> returns a <code><a href="/reference/androidx/paging/PagingSource.LoadResult.html">LoadResult</a></code> which signals a boundary condition, i.e., the most recent <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html">LoadResult.Page</a></code> in the <code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> or <code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> direction has <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html#prevKey()">LoadResult.Page.prevKey</a></code> or <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html#nextKey()">LoadResult.Page.nextKey</a></code> set to <code>null</code> respectively.</p>
</li>
</ul>
<p>It is the responsibility of this method to update the backing dataset and trigger <code><a href="/reference/androidx/paging/PagingSource.html#invalidate()">PagingSource.invalidate</a></code> to allow <code><a href="/reference/androidx/paging/PagingDataAdapter.html">androidx.paging.PagingDataAdapter</a></code> to pick up new items found by <code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a></code>.</p>
<p>The runtime and result of this method defines the remote <code><a href="/reference/androidx/paging/LoadState.html">LoadState</a></code> behavior sent to the UI via <code><a href="/reference/androidx/paging/CombinedLoadStates.html">CombinedLoadStates</a></code>.</p>
<p>This method is never called concurrently <em>unless</em> <code><a href="/reference/androidx/paging/Pager.html#flow()">Pager.flow</a></code> has multiple collectors. Note that Paging might cancel calls to this function if it is currently executing a <code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> or <code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> and a <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> is requested. In that case, <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> has higher priority and will be executed after the previous call is cancelled. If the <code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a></code> call with <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> returns an error, Paging will call <code><a href="/reference/androidx/paging/RemoteMediator.html#load(androidx.paging.LoadType,androidx.paging.PagingState)">load</a></code> with the previously cancelled <code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> or <code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> request. If <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> succeeds, it won't make the <code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> or <code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> requests unless they are necessary again after the <code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> is applied to the UI.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/LoadType.html">LoadType</a>&nbsp;loadType</code></td>
<td>
<p><code><a href="/reference/androidx/paging/LoadType.html">LoadType</a></code> of the condition which triggered this callback.</p>
<ul>
<li>
<p><code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> indicates the end of pagination in the <code><a href="/reference/androidx/paging/LoadType.html#PREPEND">PREPEND</a></code> direction was reached. This occurs when <code><a href="/reference/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code> returns a <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html">LoadResult.Page</a></code> with <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html#prevKey()">LoadResult.Page.prevKey</a></code> == <code>null</code>.</p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> indicates the end of pagination in the <code><a href="/reference/androidx/paging/LoadType.html#APPEND">APPEND</a></code> direction was reached. This occurs when <code><a href="/reference/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code> returns a <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html">LoadResult.Page</a></code> with <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.html#nextKey()">LoadResult.Page.nextKey</a></code> == <code>null</code>.</p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/LoadType.html#REFRESH">REFRESH</a></code> indicates this method was triggered due to a requested refresh. Generally, this means that a request to load remote data and <b>replace</b> all local data was made. This can happen when:</p>
</li>
<ul>
<li>
<p>Stream initialization if <code><a href="/reference/androidx/paging/RemoteMediator.html#initialize()">initialize</a></code> returns <code><a href="/reference/androidx/paging/RemoteMediator.InitializeAction.html#LAUNCH_INITIAL_REFRESH">LAUNCH_INITIAL_REFRESH</a></code></p>
</li>
<li>
<p>An explicit call to refresh driven by the UI</p>
</li>
</ul>
</ul>
</td>
</tr>
<tr>
<td width="40%"><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/PagingState.html">PagingState</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Key,&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Value&gt;&nbsp;state</code></td>
<td>
<p>A copy of the state including the list of pages currently held in memory of the currently presented <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> at the time of starting the load. E.g. for load(loadType = APPEND), you can use the page or item at the end as input for what to load from the network.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Returns</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td width="40%"><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/paging/RemoteMediator.MediatorResult.html">RemoteMediator.MediatorResult</a></code></td>
<td>
<p><code><a href="/reference/androidx/paging/RemoteMediator.MediatorResult.html">MediatorResult</a></code> signifying what <code><a href="/reference/androidx/paging/LoadState.html">LoadState</a></code> to be passed to the UI, and whether there's more data available.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>