blob: 255523e69548e09b07fbacc0120725e920f83dc8 [file] [log] [blame]
Alex Saveaue60da312020-09-09 23:34:43 +00001<html devsite="true">
2 <head>
3 <title>PagingSource</title>
4{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %}
5{% include "_shared/_reference-head-tags.html" %}
6 </head>
7 <body>
Tiem Song6f896de2022-11-03 14:55:52 -07008 <div id="metadata-info-block"></div>
Alex Saveaue60da312020-09-09 23:34:43 +00009 <h1>PagingSource</h1>
Andrea Falcone4be8b872020-10-15 12:34:30 -040010 <p>
Owen Gray22f20572022-08-08 13:48:02 -040011 <pre>abstract class <a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</pre>
Andrea Falcone4be8b872020-10-15 12:34:30 -040012 </p>
Alex Saveau20bf0662020-09-23 03:45:51 +000013 <div class="devsite-table-wrapper"><devsite-expandable><span class="expand-control jd-sumtable-subclasses">Known direct subclasses
14 <div class="showalways" id="subclasses-direct"><a href="/reference/kotlin/androidx/paging/ListenableFuturePagingSource.html">ListenableFuturePagingSource</a>, <a href="/reference/kotlin/androidx/paging/rxjava2/RxPagingSource.html">RxPagingSource</a>, <a href="/reference/kotlin/androidx/paging/rxjava3/RxPagingSource.html">RxPagingSource</a></div>
15 </span>
16 <div id="subclasses-direct-summary">
17 <div class="devsite-table-wrapper">
18 <table class="responsive">
Andrea Falcone80f1a8f2022-08-23 11:22:33 -040019 <tbody class="list">
Alex Saveau20bf0662020-09-23 03:45:51 +000020 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -040021 <td width="40%"><code><a href="/reference/kotlin/androidx/paging/ListenableFuturePagingSource.html">ListenableFuturePagingSource</a></code></td>
22 <td>
Paweł Marks4724d6f2021-12-22 17:11:51 +010023 <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/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>'s suspending APIs.</p>
Alex Saveau20bf0662020-09-23 03:45:51 +000024 </td>
25 </tr>
26 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -040027 <td width="40%"><code><a href="/reference/kotlin/androidx/paging/rxjava2/RxPagingSource.html">RxPagingSource</a></code></td>
28 <td>
Alex Saveau20bf0662020-09-23 03:45:51 +000029 <p>Rx-based compatibility wrapper around <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>'s suspending APIs.</p>
30 </td>
31 </tr>
32 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -040033 <td width="40%"><code><a href="/reference/kotlin/androidx/paging/rxjava3/RxPagingSource.html">RxPagingSource</a></code></td>
34 <td>
Alex Saveau20bf0662020-09-23 03:45:51 +000035 <p>Rx-based compatibility wrapper around <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>'s suspending APIs.</p>
36 </td>
37 </tr>
38 </tbody>
39 </table>
40 </div>
41 </div>
42</devsite-expandable> </div>
Alex Saveaue60da312020-09-09 23:34:43 +000043 <hr>
Alex Saveaufe9fe472020-09-10 01:41:31 +000044 <p>Base class for an abstraction of pageable static data from some source, where loading pages of data is typically an expensive operation. Some examples of common <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>s might be from network or from a database.</p>
45 <p>An instance of a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> is used to load pages of data for an instance of <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code>.</p>
46 <p>A <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> can grow as it loads more data, but the data loaded cannot be updated. If the underlying data set is modified, a new <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> pair must be created to represent an updated snapshot of the data.</p>
47 <h3> Loading Pages</h3>
48 <p><code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> queries data from its <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> in response to loading hints generated as the user scrolls in a <code>RecyclerView</code>.</p>
Alex Saveau7ffa75d2020-09-19 05:45:27 +000049 <p>To control how and when a <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> queries data from its <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>, see <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html">PagingConfig</a></code>, which defines behavior such as <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#pageSize()">PagingConfig.pageSize</a></code> and <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#prefetchDistance()">PagingConfig.prefetchDistance</a></code>.</p>
Alex Saveaufe9fe472020-09-10 01:41:31 +000050 <h3> Updating Data</h3>
51 <p>A <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> pair is a snapshot of the data set. A new <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> must be created if an update occurs, such as a reorder, insert, delete, or content update occurs. A <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> must detect that it cannot continue loading its snapshot (for instance, when Database query notices a table being invalidated), and call <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>. Then a new <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> pair would be created to represent data from the new state of the database query.</p>
52 <h3> Presenting Data to UI</h3>
53 <p>To present data loaded by a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> to a <code>RecyclerView</code>, create an instance of <code><a href="/reference/kotlin/androidx/paging/Pager.html">Pager</a></code>, which provides a stream of <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> that you may collect from and submit to a <code><a href="/reference/kotlin/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code>.</p>
Owen Grayeb256132021-01-27 13:49:50 -050054 <pre class="prettyprint">/**
Owen Gray327bd5c2021-03-23 10:21:18 -040055 * Sample page-keyed PagingSource, which uses Int page number to load pages.
Owen Grayeb256132021-01-27 13:49:50 -050056 *
57 * Loads Items from network requests via Retrofit to a backend service.
58 *
59 * Note that the key type is Int, since we're using page number to load a page.
60 */
61class MyPagingSource(
62 val myBackend: MyBackendService
63) : PagingSource&lt;Int, Item&gt;() {
64 override suspend fun load(params: LoadParams&lt;Int&gt;): LoadResult&lt;Int, Item&gt; {
65
66 // Retrofit calls that return the body type throw either IOException for network
67 // failures, or HttpException for any non-2xx HTTP status codes. This code reports all
68 // errors to the UI, but you can inspect/wrap the exceptions to provide more context.
69 return try {
70 // Key may be null during a refresh, if no explicit key is passed into Pager
71 // construction. Use 0 as default, because our API is indexed started at index 0
72 val pageNumber = params.key ?: 0
73
74 // Suspending network load via Retrofit. This doesn't need to be wrapped in a
75 // withContext(Dispatcher.IO) { ... } block since Retrofit's Coroutine
76 // CallAdapter dispatches on a worker thread.
77 val response = myBackend.searchItems(pageNumber)
78
79 // Since 0 is the lowest page number, return null to signify no more pages should
80 // be loaded before it.
81 val prevKey = if (pageNumber &gt; 0) pageNumber - 1 else null
82
83 // This API defines that it's out of data when a page returns empty. When out of
84 // data, we return `null` to signify no more pages should be loaded
85 val nextKey = if (response.items.isNotEmpty()) pageNumber + 1 else null
86 LoadResult.Page(
87 data = response.items,
88 prevKey = prevKey,
89 nextKey = nextKey
90 )
91 } catch (e: IOException) {
92 LoadResult.Error(e)
93 } catch (e: HttpException) {
94 LoadResult.Error(e)
95 }
96 }
97
98 override fun getRefreshKey(state: PagingState&lt;Int, Item&gt;): Int? {
99 return state.anchorPosition?.let {
100 state.closestPageToPosition(it)?.prevKey?.plus(1)
101 ?: state.closestPageToPosition(it)?.nextKey?.minus(1)
102 }
103 }
104}</pre>
Owen Gray327bd5c2021-03-23 10:21:18 -0400105 <pre class="prettyprint">/**
106 * Sample item-keyed [PagingSource], which uses String tokens to load pages.
107 *
108 * Loads Items from network requests via Retrofit to a backend service.
109 */
110class MyPagingSource(
111 val myBackend: MyBackendService
112) : PagingSource&lt;String, Item&gt;() {
113 override suspend fun load(params: LoadParams&lt;String&gt;): LoadResult&lt;String, Item&gt; {
114 // Retrofit calls that return the body type throw either IOException for network
115 // failures, or HttpException for any non-2xx HTTP status codes. This code reports all
116 // errors to the UI, but you can inspect/wrap the exceptions to provide more context.
117 return try {
118 // Suspending network load via Retrofit. This doesn't need to be wrapped in a
119 // withContext(Dispatcher.IO) { ... } block since Retrofit's Coroutine
120 // CallAdapter dispatches on a worker thread.
121 val response = myBackend.searchItems(params.key)
122 LoadResult.Page(
123 data = response.items,
124 prevKey = response.prev,
125 nextKey = response.next
126 )
127 } catch (e: IOException) {
128 LoadResult.Error(e)
129 } catch (e: HttpException) {
130 LoadResult.Error(e)
131 }
132 }
133
134 override fun getRefreshKey(state: PagingState&lt;String, Item&gt;): String? {
135 return state.anchorPosition?.let { state.closestItemToPosition(it)?.id }
136 }
137}</pre>
Alex Saveaue60da312020-09-09 23:34:43 +0000138 <div class="devsite-table-wrapper">
139 <table class="responsive">
140 <thead>
141 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400142 <th colspan="100%">Parameters</th>
Alex Saveaue60da312020-09-09 23:34:43 +0000143 </tr>
144 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400145 <tbody class="list">
Alex Saveaue60da312020-09-09 23:34:43 +0000146 <tr>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100147 <td width="40%"><code>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400148 <td>
Andrea Falcone3adcc282020-12-04 09:31:29 -0500149 <p>Type of key which define what data to load. E.g. <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code> to represent either a page number or item position, or <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html">String</a></code> if your network uses Strings as next tokens returned with each response.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000150 </td>
151 </tr>
152 <tr>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100153 <td width="40%"><code>&lt;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400154 <td>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000155 <p>Type of data loaded in by this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>. E.g., the type of data that will be passed to a <code><a href="/reference/kotlin/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code> to be displayed in a <code>RecyclerView</code>.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000156 </td>
157 </tr>
158 </tbody>
159 </table>
160 </div>
161 <div class="devsite-table-wrapper">
162 <table class="responsive">
163 <thead>
164 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400165 <th colspan="100%">See also</th>
Alex Saveaue60da312020-09-09 23:34:43 +0000166 </tr>
167 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400168 <tbody class="list">
Alex Saveaue60da312020-09-09 23:34:43 +0000169 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400170 <td width="40%"><code><a href="/reference/kotlin/androidx/paging/Pager.html">Pager</a></code></td>
171 <td></td>
Alex Saveaue60da312020-09-09 23:34:43 +0000172 </tr>
173 </tbody>
174 </table>
175 </div>
176 <h2>Summary</h2>
Alex Saveaue60da312020-09-09 23:34:43 +0000177 <div class="devsite-table-wrapper">
178 <table class="responsive">
179 <thead>
180 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400181 <th colspan="100%"><h3>Nested types</h3></th>
Alex Saveau66428452020-09-17 22:44:07 +0000182 </tr>
183 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400184 <tbody class="list">
Alex Saveau66428452020-09-17 22:44:07 +0000185 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400186 <td width="40%"><code>sealed class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400187 <td>
Alex Saveau3555c952020-09-18 03:05:17 +0000188 <p>Params for a load request on a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> from <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code>.</p>
Alex Saveau66428452020-09-17 22:44:07 +0000189 </td>
190 </tr>
191 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400192 <td width="40%"><code>class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.Append.html">PagingSource.LoadParams.Append</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; : <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400193 <td>
Alex Saveau3555c952020-09-18 03:05:17 +0000194 <p>Params to load a page of data from a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> via <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code> to be appended to the end of the list.</p>
Alex Saveau66428452020-09-17 22:44:07 +0000195 </td>
196 </tr>
197 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400198 <td width="40%"><code>class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.Prepend.html">PagingSource.LoadParams.Prepend</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; : <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400199 <td>
Alex Saveau3555c952020-09-18 03:05:17 +0000200 <p>Params to load a page of data from a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> via <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code> to be prepended to the start of the list.</p>
Alex Saveau66428452020-09-17 22:44:07 +0000201 </td>
202 </tr>
203 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400204 <td width="40%"><code>class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.Refresh.html">PagingSource.LoadParams.Refresh</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; : <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400205 <td>
Alex Saveau3555c952020-09-18 03:05:17 +0000206 <p>Params for an initial load request on a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> from <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code> or a refresh triggered by <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>.</p>
Alex Saveau66428452020-09-17 22:44:07 +0000207 </td>
208 </tr>
209 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400210 <td width="40%"><code>sealed class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400211 <td>
Alex Saveau3555c952020-09-18 03:05:17 +0000212 <p>Result of a load request from <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code>.</p>
Alex Saveau66428452020-09-17 22:44:07 +0000213 </td>
214 </tr>
215 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400216 <td width="40%"><code>data class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.Error.html">PagingSource.LoadResult.Error</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; : <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400217 <td>
Alex Saveau3555c952020-09-18 03:05:17 +0000218 <p>Error result object for <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code>.</p>
Alex Saveau66428452020-09-17 22:44:07 +0000219 </td>
220 </tr>
221 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400222 <td width="40%"><code>class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.Invalid.html">PagingSource.LoadResult.Invalid</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; : <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a></code></td>
Owen Grayc2f8bde2022-04-25 13:17:41 -0400223 <td>
224 <p>Invalid result object for <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code></p>
225 </td>
226 </tr>
227 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400228 <td width="40%"><code>data class <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page.html">PagingSource.LoadResult.Page</a>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; : <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400229 <td>
Alex Saveau3555c952020-09-18 03:05:17 +0000230 <p>Success result object for <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">PagingSource.load</a></code>.</p>
Alex Saveau66428452020-09-17 22:44:07 +0000231 </td>
232 </tr>
233 <tr>
Owen Gray22f20572022-08-08 13:48:02 -0400234 <td width="40%"><code>object <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page.Companion.html">PagingSource.LoadResult.Page.Companion</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400235 <td></td>
Alex Saveau66428452020-09-17 22:44:07 +0000236 </tr>
237 </tbody>
238 </table>
239 </div>
240 <div class="devsite-table-wrapper">
241 <table class="responsive">
242 <thead>
243 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400244 <th colspan="100%"><h3>Public constructors</h3></th>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000245 </tr>
246 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400247 <tbody class="list">
Alex Saveauf393e9a2020-09-17 21:15:59 +0000248 <tr>
249 <td>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100250 <div><code>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/PagingSource.html#PagingSource()">PagingSource</a>()</code></div>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000251 </td>
252 </tr>
253 </tbody>
254 </table>
255 </div>
256 <div class="devsite-table-wrapper">
257 <table class="responsive">
258 <thead>
259 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400260 <th colspan="100%"><h3>Public functions</h3></th>
Alex Saveaue60da312020-09-09 23:34:43 +0000261 </tr>
262 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400263 <tbody class="list">
Alex Saveaue60da312020-09-09 23:34:43 +0000264 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400265 <td width="40%"><code>abstract Key?</code></td>
266 <td>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100267 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a>(state:&nbsp;<a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a>&lt;Key,&nbsp;Value&gt;)</code></div>
Owen Gray327bd5c2021-03-23 10:21:18 -0400268 <p>Provide a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> used for the initial <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a></code> for the next <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> due to invalidation of this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000269 </td>
270 </tr>
271 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400272 <td width="40%"><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
273 <td>
Alex Saveaue60da312020-09-09 23:34:43 +0000274 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a>()</code></div>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000275 <p>Signal the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> to stop loading.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000276 </td>
277 </tr>
278 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400279 <td width="40%"><code>abstract&nbsp;suspend <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a>&lt;Key,&nbsp;Value&gt;</code></td>
280 <td>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100281 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a>(params:&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a>&lt;Key&gt;)</code></div>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000282 <p>Loading API for <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000283 </td>
284 </tr>
285 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400286 <td width="40%"><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
287 <td>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100288 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#registerInvalidatedCallback(kotlin.Function0)">registerInvalidatedCallback</a>(onInvalidatedCallback:&nbsp;() <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>)</code></div>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000289 <p>Add a callback to invoke when the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> is first invalidated.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000290 </td>
291 </tr>
292 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400293 <td width="40%"><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
294 <td>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100295 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#unregisterInvalidatedCallback(kotlin.Function0)">unregisterInvalidatedCallback</a>(onInvalidatedCallback:&nbsp;() <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>)</code></div>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000296 <p>Remove a previously added invalidate callback.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000297 </td>
298 </tr>
299 </tbody>
300 </table>
301 </div>
Fred Sladkey375e2ba2021-05-26 20:13:00 +0000302 <div class="devsite-table-wrapper">
303 <table class="responsive">
304 <thead>
305 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400306 <th colspan="100%"><h3>Public properties</h3></th>
Fred Sladkey375e2ba2021-05-26 20:13:00 +0000307 </tr>
308 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400309 <tbody class="list">
Fred Sladkey375e2ba2021-05-26 20:13:00 +0000310 <tr>
311 <td width="40%"><code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
312 <td>
313 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalid()">invalid</a></code></div>
314 <p>Whether this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> has been invalidated, which should happen when the data this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> represents changes since it was first instantiated.</p>
315 </td>
316 </tr>
317 <tr>
318 <td width="40%"><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
319 <td>
320 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#jumpingSupported()">jumpingSupported</a></code></div>
321 <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> supports jumping, <code>false</code> otherwise.</p>
322 </td>
323 </tr>
324 <tr>
325 <td width="40%"><code>open <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></code></td>
326 <td>
327 <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#keyReuseSupported()">keyReuseSupported</a></code></div>
328 <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> expects to re-use keys to load distinct pages without a call to <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>, <code>false</code> otherwise.</p>
329 </td>
330 </tr>
331 </tbody>
332 </table>
Alex Saveau65f73172020-09-09 22:46:21 +0000333 </div>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000334 <h2>Public constructors</h2>
Fred Sladkey86625e32021-05-24 19:28:27 -0400335 <div><a name="PagingSource--"></a><a name="pagingsource"></a>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000336 <h3 class="api-name" id="PagingSource()">PagingSource</h3>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100337 <pre class="api-signature no-pretty-print">&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>,&nbsp;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt; <a href="/reference/kotlin/androidx/paging/PagingSource.html#PagingSource()">PagingSource</a>()</pre>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000338 <div class="devsite-table-wrapper">
339 <table class="responsive">
340 <thead>
341 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400342 <th colspan="100%">Parameters</th>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000343 </tr>
344 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400345 <tbody class="list">
Alex Saveauf393e9a2020-09-17 21:15:59 +0000346 <tr>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100347 <td width="40%"><code>&lt;Key&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400348 <td>
Andrea Falcone3adcc282020-12-04 09:31:29 -0500349 <p>Type of key which define what data to load. E.g. <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html">Int</a></code> to represent either a page number or item position, or <code><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html">String</a></code> if your network uses Strings as next tokens returned with each response.</p>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000350 </td>
351 </tr>
352 <tr>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100353 <td width="40%"><code>&lt;Value&nbsp;:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html">Any</a>&gt;</code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400354 <td>
Alex Saveauf393e9a2020-09-17 21:15:59 +0000355 <p>Type of data loaded in by this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>. E.g., the type of data that will be passed to a <code><a href="/reference/kotlin/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code> to be displayed in a <code>RecyclerView</code>.</p>
356 </td>
357 </tr>
358 </tbody>
359 </table>
360 </div>
361 </div>
Alex Saveaue60da312020-09-09 23:34:43 +0000362 <h2>Public functions</h2>
Fred Sladkey86625e32021-05-24 19:28:27 -0400363 <div><a name="getRefreshKey-androidx.paging.PagingState-"></a><a name="getrefreshkey"></a>
Alex Saveaue60da312020-09-09 23:34:43 +0000364 <h3 class="api-name" id="getRefreshKey(androidx.paging.PagingState)">getRefreshKey</h3>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100365 <pre class="api-signature no-pretty-print">abstract&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a>(state:&nbsp;<a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a>&lt;Key,&nbsp;Value&gt;):&nbsp;Key?</pre>
Owen Gray327bd5c2021-03-23 10:21:18 -0400366 <p>Provide a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> used for the initial <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a></code> for the next <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> due to invalidation of this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>. The <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> is provided to <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a></code> via <code><a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html#key()">LoadParams.key</a></code>.</p>
Owen Grayc2f8bde2022-04-25 13:17:41 -0400367 <p>The <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> returned by this method should cause <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a></code> to load enough items to fill the viewport <em>around</em> the last accessed position, allowing the next generation to transparently animate in. The last accessed position can be retrieved via <code><a href="/reference/kotlin/androidx/paging/PagingState.html#anchorPosition()">state.anchorPosition</a></code>, which is typically the <em>top-most</em> or <em>bottom-most</em> item in the viewport due to access being triggered by binding items as they scroll into view.</p>
368 <p>For example, if items are loaded based on integer position keys, you can return <code>( (state.anchorPosition ?: 0) - state.config.initialLoadSize / 2).coerceAtLeast(0)</code>.</p>
369 <p>Alternately, if items contain a key used to load, get the key from the item in the page at index <code><a href="/reference/kotlin/androidx/paging/PagingState.html#anchorPosition()">state.anchorPosition</a></code> then try to center it based on <code>state.config.initialLoadSize</code>.</p>
Owen Gray327bd5c2021-03-23 10:21:18 -0400370 <div class="devsite-table-wrapper">
371 <table class="responsive">
372 <thead>
373 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400374 <th colspan="100%">Parameters</th>
Owen Gray327bd5c2021-03-23 10:21:18 -0400375 </tr>
376 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400377 <tbody class="list">
Owen Gray327bd5c2021-03-23 10:21:18 -0400378 <tr>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100379 <td width="40%"><code>state:&nbsp;<a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a>&lt;Key,&nbsp;Value&gt;</code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400380 <td>
Owen Gray327bd5c2021-03-23 10:21:18 -0400381 <p><code><a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a></code> of the currently fetched data, which includes the most recently accessed position in the list via <code><a href="/reference/kotlin/androidx/paging/PagingState.html#anchorPosition()">PagingState.anchorPosition</a></code>.</p>
382 </td>
383 </tr>
384 </tbody>
385 </table>
386 </div>
387 <div class="devsite-table-wrapper">
388 <table class="responsive">
389 <thead>
390 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400391 <th colspan="100%">Returns</th>
Owen Gray327bd5c2021-03-23 10:21:18 -0400392 </tr>
393 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400394 <tbody class="list">
Owen Gray327bd5c2021-03-23 10:21:18 -0400395 <tr>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400396 <td width="40%"><code>Key?</code></td>
397 <td>
Owen Gray327bd5c2021-03-23 10:21:18 -0400398 <p><code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> passed to <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a></code> after invalidation used for initial load of the next generation. The <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> returned by <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a></code> should load pages centered around user's current viewport. If the correct <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> cannot be determined, <code>null</code> can be returned to allow <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a></code> decide what default key to use.</p>
399 </td>
400 </tr>
401 </tbody>
402 </table>
403 </div>
Alex Saveaue60da312020-09-09 23:34:43 +0000404 </div>
Fred Sladkey86625e32021-05-24 19:28:27 -0400405 <div><a name="invalidate--"></a><a name="invalidate"></a>
Alex Saveaue60da312020-09-09 23:34:43 +0000406 <h3 class="api-name" id="invalidate()">invalidate</h3>
Owen Gray327bd5c2021-03-23 10:21:18 -0400407 <pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a>():&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000408 <p>Signal the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> to stop loading.</p>
409 <p>This method is idempotent. i.e., If <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code> has already been called, subsequent calls to this method should have no effect.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000410 </div>
Fred Sladkey86625e32021-05-24 19:28:27 -0400411 <div><a name="load-androidx.paging.PagingSource.LoadParams-"></a><a name="load"></a>
Alex Saveaue60da312020-09-09 23:34:43 +0000412 <h3 class="api-name" id="load(androidx.paging.PagingSource.LoadParams)">load</h3>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100413 <pre class="api-signature no-pretty-print">abstract&nbsp;suspend&nbsp;fun&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a>(params:&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a>&lt;Key&gt;):&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a>&lt;Key,&nbsp;Value&gt;</pre>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000414 <p>Loading API for <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
415 <p>Implement this method to trigger your async load (e.g. from database or network).</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000416 </div>
Fred Sladkey86625e32021-05-24 19:28:27 -0400417 <div><a name="registerInvalidatedCallback-kotlin.Function0-"></a><a name="registerinvalidatedcallback"></a>
Alex Saveaue60da312020-09-09 23:34:43 +0000418 <h3 class="api-name" id="registerInvalidatedCallback(kotlin.Function0)">registerInvalidatedCallback</h3>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100419 <pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#registerInvalidatedCallback(kotlin.Function0)">registerInvalidatedCallback</a>(onInvalidatedCallback:&nbsp;() <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000420 <p>Add a callback to invoke when the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> is first invalidated.</p>
421 <p>Once invalidated, a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> will not become valid again.</p>
422 <p>A <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> will only invoke its callbacks once - the first time <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code> is called, on that thread.</p>
Owen Grayc2f8bde2022-04-25 13:17:41 -0400423 <p>If this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> is already invalid, the provided <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#registerInvalidatedCallback(kotlin.Function0)">onInvalidatedCallback</a></code> will be triggered immediately.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000424 <div class="devsite-table-wrapper">
425 <table class="responsive">
426 <thead>
427 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400428 <th colspan="100%">Parameters</th>
Alex Saveaue60da312020-09-09 23:34:43 +0000429 </tr>
430 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400431 <tbody class="list">
Alex Saveaue60da312020-09-09 23:34:43 +0000432 <tr>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100433 <td width="40%"><code>onInvalidatedCallback:&nbsp;() <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400434 <td>
Alex Saveaue60da312020-09-09 23:34:43 +0000435 <p>The callback that will be invoked on thread that invalidates the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
436 </td>
437 </tr>
438 </tbody>
439 </table>
440 </div>
441 </div>
Fred Sladkey86625e32021-05-24 19:28:27 -0400442 <div><a name="unregisterInvalidatedCallback-kotlin.Function0-"></a><a name="unregisterinvalidatedcallback"></a>
Alex Saveaue60da312020-09-09 23:34:43 +0000443 <h3 class="api-name" id="unregisterInvalidatedCallback(kotlin.Function0)">unregisterInvalidatedCallback</h3>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100444 <pre class="api-signature no-pretty-print">fun&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#unregisterInvalidatedCallback(kotlin.Function0)">unregisterInvalidatedCallback</a>(onInvalidatedCallback:&nbsp;() <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a>):&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></pre>
Alex Saveaufe9fe472020-09-10 01:41:31 +0000445 <p>Remove a previously added invalidate callback.</p>
Alex Saveaue60da312020-09-09 23:34:43 +0000446 <div class="devsite-table-wrapper">
447 <table class="responsive">
448 <thead>
449 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400450 <th colspan="100%">Parameters</th>
Alex Saveaue60da312020-09-09 23:34:43 +0000451 </tr>
452 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400453 <tbody class="list">
Alex Saveaue60da312020-09-09 23:34:43 +0000454 <tr>
Paweł Marks4724d6f2021-12-22 17:11:51 +0100455 <td width="40%"><code>onInvalidatedCallback:&nbsp;() <span style="white-space: nowrap;">-&gt;</span> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a></code></td>
Andrea Falconed77cf9d2021-04-26 17:34:56 -0400456 <td>
Alex Saveaue60da312020-09-09 23:34:43 +0000457 <p>The previously added callback.</p>
458 </td>
459 </tr>
460 </tbody>
461 </table>
462 </div>
463 </div>
Fred Sladkey375e2ba2021-05-26 20:13:00 +0000464 <h2>Public properties</h2>
465 <div><a name="getInvalid()"></a><a name="setInvalid()"></a><a name="getInvalid--"></a><a name="setInvalid--"></a>
466 <h3 class="api-name" id="invalid()">invalid</h3>
467 <pre class="api-signature no-pretty-print">val&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#invalid()">invalid</a>:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
468 <p>Whether this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> has been invalidated, which should happen when the data this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> represents changes since it was first instantiated.</p>
469 </div>
470 <div><a name="getJumpingSupported()"></a><a name="setJumpingSupported()"></a><a name="getJumpingSupported--"></a><a name="setJumpingSupported--"></a>
471 <h3 class="api-name" id="jumpingSupported()">jumpingSupported</h3>
472 <pre class="api-signature no-pretty-print">open&nbsp;val&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#jumpingSupported()">jumpingSupported</a>:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
473 <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> supports jumping, <code>false</code> otherwise.</p>
474 <p>Override this to <code>true</code> if pseudo-fast scrolling via jumps is supported.</p>
Fred Sladkey6b33bca2021-06-01 17:39:06 +0000475 <p>A jump occurs when a <code>RecyclerView</code> scrolls through a number of placeholders defined by <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#jumpThreshold()">PagingConfig.jumpThreshold</a></code> and triggers a load with <code><a href="/reference/kotlin/androidx/paging/LoadType.html#REFRESH">LoadType</a></code>.</p>
Fred Sladkey375e2ba2021-05-26 20:13:00 +0000476 <p><code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>s that support jumps should override <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a></code> to return a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">Key</a></code> that would load data fulfilling the viewport given a user's current <code><a href="/reference/kotlin/androidx/paging/PagingState.html#anchorPosition()">PagingState.anchorPosition</a></code>.</p>
477 <div class="devsite-table-wrapper">
478 <table class="responsive">
479 <thead>
480 <tr>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400481 <th colspan="100%">See also</th>
Fred Sladkey375e2ba2021-05-26 20:13:00 +0000482 </tr>
483 </thead>
Andrea Falcone80f1a8f2022-08-23 11:22:33 -0400484 <tbody class="list">
Fred Sladkey375e2ba2021-05-26 20:13:00 +0000485 <tr>
486 <td width="40%"><code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#jumpThreshold()">jumpThreshold</a></code></td>
487 <td></td>
488 </tr>
489 </tbody>
490 </table>
491 </div>
492 </div>
493 <div><a name="getKeyReuseSupported()"></a><a name="setKeyReuseSupported()"></a><a name="getKeyReuseSupported--"></a><a name="setKeyReuseSupported--"></a>
494 <h3 class="api-name" id="keyReuseSupported()">keyReuseSupported</h3>
495 <pre class="api-signature no-pretty-print">open&nbsp;val&nbsp;<a href="/reference/kotlin/androidx/paging/PagingSource.html#keyReuseSupported()">keyReuseSupported</a>:&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html">Boolean</a></pre>
496 <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> expects to re-use keys to load distinct pages without a call to <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>, <code>false</code> otherwise.</p>
497 </div>
Alex Saveaue60da312020-09-09 23:34:43 +0000498 </body>
499</html>