blob: bc861830f8de00694b81607090d773c6181b9eaf [file] [log] [blame]
<html devsite="true">
<head>
<title>PagingConfig</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>PagingConfig</h1>
{% setvar page_path %}androidx/paging/PagingConfig.html{% endsetvar %}
{% setvar can_switch %}1{% endsetvar %}
{% include "reference/_java_switcher2.md" %}
<p>TODO(b/166518424) class signature</p>
<hr>
<p>An object used to configure loading behavior within a <code><a href="/reference/androidx/paging/Pager.html">Pager</a></code>, as it loads content from a <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Nested types</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/androidx/paging/PagingConfig.Companion.html">PagingConfig.Companion</a></code></td>
<td width="100%"></td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public fields</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>final boolean</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/PagingConfig.html#enablePlaceholders()">enablePlaceholders</a></code></div>
<p>Defines whether <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> may display <code>null</code> placeholders, if the <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> provides them.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/PagingConfig.html#initialLoadSize()">initialLoadSize</a></code></div>
<p>Defines requested load size for initial load from <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>, typically larger than <code><a href="/reference/androidx/paging/PagingConfig.html#pageSize()">pageSize</a></code>, so on first load data there's a large enough range of content loaded to cover small scrolls.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/PagingConfig.html#jumpThreshold()">jumpThreshold</a></code></div>
<p>Threshold for number of items scrolled outside the bounds of loaded items to trigger invalidate.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/PagingConfig.html#maxSize()">maxSize</a></code></div>
<p>Defines the maximum number of items that may be loaded into <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> before pages should be dropped.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/PagingConfig.html#pageSize()">pageSize</a></code></div>
<p>Defines the number of items loaded at once from the <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
</td>
</tr>
<tr>
<td><code>final int</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/PagingConfig.html#prefetchDistance()">prefetchDistance</a></code></div>
<p>Prefetch distance which defines how far from the edge of loaded content an access must be to trigger further loading.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div><code><a href="/reference/androidx/paging/PagingConfig.html#PagingConfig(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)">PagingConfig</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;int&nbsp;pageSize,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;@<a href="/reference/kotlin/ranges/IntRange.html">IntRange</a>&nbsp;int&nbsp;prefetchDistance,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;boolean&nbsp;enablePlaceholders,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;@<a href="/reference/kotlin/ranges/IntRange.html">IntRange</a>&nbsp;int&nbsp;initialLoadSize,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;@<a href="/reference/kotlin/ranges/IntRange.html">IntRange</a>&nbsp;int&nbsp;maxSize,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;int&nbsp;jumpThreshold<br>)</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Public fields</h2>
<div><a name="getEnablePlaceholders()"></a><a name="setEnablePlaceholders()"></a><a name="getEnablePlaceholders--"></a><a name="setEnablePlaceholders--"></a>
<h3 class="api-name" id="enablePlaceholders()">enablePlaceholders</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;boolean&nbsp;<a href="/reference/androidx/paging/PagingConfig.html#enablePlaceholders()">enablePlaceholders</a></pre>
<p>Defines whether <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> may display <code>null</code> placeholders, if the <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> provides them.</p>
<p><code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> will present <code>null</code> placeholders for not-yet-loaded content if two conditions are met:</p>
<ol>
<li>
<p>Its <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> can count all unloaded items (so that the number of nulls to present is known).</p>
</li>
<li>
<p><code><a href="/reference/androidx/paging/PagingConfig.html#enablePlaceholders()">enablePlaceholders</a></code> is set to <code>true</code></p>
</li>
</ol>
</div>
<div><a name="getInitialLoadSize()"></a><a name="setInitialLoadSize()"></a><a name="getInitialLoadSize--"></a><a name="setInitialLoadSize--"></a>
<h3 class="api-name" id="initialLoadSize()">initialLoadSize</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/paging/PagingConfig.html#initialLoadSize()">initialLoadSize</a></pre>
<p>Defines requested load size for initial load from <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>, typically larger than <code><a href="/reference/androidx/paging/PagingConfig.html#pageSize()">pageSize</a></code>, so on first load data there's a large enough range of content loaded to cover small scrolls.</p>
</div>
<div><a name="getJumpThreshold()"></a><a name="setJumpThreshold()"></a><a name="getJumpThreshold--"></a><a name="setJumpThreshold--"></a>
<h3 class="api-name" id="jumpThreshold()">jumpThreshold</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/paging/PagingConfig.html#jumpThreshold()">jumpThreshold</a></pre>
<p>Threshold for number of items scrolled outside the bounds of loaded items to trigger invalidate. Defaults to <code><a href="/reference/androidx/paging/PagingSource.LoadResult.Page.Companion.html#COUNT_UNDEFINED()">COUNT_UNDEFINED</a></code>, which disables invalidation due to scrolling large distances.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a></code></td>
<td width="100%">
<p></p>
</td>
</tr>
<tr>
<td><code><a href="/reference/androidx/paging/PagingSource.html#jumpingSupported()">jumpingSupported</a></code></td>
<td width="100%">
<p></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="getMaxSize()"></a><a name="setMaxSize()"></a><a name="getMaxSize--"></a><a name="setMaxSize--"></a>
<h3 class="api-name" id="maxSize()">maxSize</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/paging/PagingConfig.html#maxSize()">maxSize</a></pre>
<p>Defines the maximum number of items that may be loaded into <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> before pages should be dropped.</p>
<p>If set to <code><a href="/reference/androidx/paging/PagingConfig.Companion.html#MAX_SIZE_UNBOUNDED()">MAX_SIZE_UNBOUNDED</a></code>, pages will never be dropped.</p>
<p>This can be used to cap the number of items kept in memory by dropping pages. This value is typically many pages so old pages are cached in case the user scrolls back.</p>
<p>This value must be at least two times the <code><a href="/reference/androidx/paging/PagingConfig.html#prefetchDistance()">prefetchDistance</a></code> plus the <code><a href="/reference/androidx/paging/PagingConfig.html#pageSize()">pageSize</a></code>). This constraint prevent loads from being continuously fetched and discarded due to prefetching.</p>
<p><code><a href="/reference/androidx/paging/PagingConfig.html#maxSize()">maxSize</a></code> is best effort, not a guarantee. In practice, if <code><a href="/reference/androidx/paging/PagingConfig.html#maxSize()">maxSize</a></code> is many times <code><a href="/reference/androidx/paging/PagingConfig.html#pageSize()">pageSize</a></code>, the number of items held by <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> will not grow above this number. Exceptions are made as necessary to guarantee:</p>
<ul>
<li>
<p>Pages are never dropped until there are more than two pages loaded. Note that a <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code> may not be held strictly to <code><a href="/reference/androidx/paging/PagingConfig.html#pageSize()">requested pageSize</a></code>, so two pages may be larger than expected.</p>
</li>
<li>
<p>Pages are never dropped if they are within a prefetch window (defined to be <code>pageSize + (2 * prefetchDistance)</code>) of the most recent load.</p>
</li>
</ul>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">See also</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/androidx/paging/PagingConfig.Companion.html#MAX_SIZE_UNBOUNDED()">MAX_SIZE_UNBOUNDED</a></code></td>
<td width="100%">
<p></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="getPageSize()"></a><a name="setPageSize()"></a><a name="getPageSize--"></a><a name="setPageSize--"></a>
<h3 class="api-name" id="pageSize()">pageSize</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/paging/PagingConfig.html#pageSize()">pageSize</a></pre>
<p>Defines the number of items loaded at once from the <code><a href="/reference/androidx/paging/PagingSource.html">PagingSource</a></code>.</p>
<p>Should be several times the number of visible items onscreen.</p>
<p>Configuring your page size depends on how your data is being loaded and used. Smaller page sizes improve memory usage, latency, and avoid GC churn. Larger pages generally improve loading throughput, to a point (avoid loading more than 2MB from SQLite at once, since it incurs extra cost).</p>
<p>If you're loading data for very large, social-media style cards that take up most of a screen, and your database isn't a bottleneck, 10-20 may make sense. If you're displaying dozens of items in a tiled grid, which can present items during a scroll much more quickly, consider closer to 100.</p>
</div>
<div><a name="getPrefetchDistance()"></a><a name="setPrefetchDistance()"></a><a name="getPrefetchDistance--"></a><a name="setPrefetchDistance--"></a>
<h3 class="api-name" id="prefetchDistance()">prefetchDistance</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;int&nbsp;<a href="/reference/androidx/paging/PagingConfig.html#prefetchDistance()">prefetchDistance</a></pre>
<p>Prefetch distance which defines how far from the edge of loaded content an access must be to trigger further loading. Typically should be set several times the number of visible items onscreen.</p>
<p>E.g., If this value is set to 50, a <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> will attempt to load 50 items in advance of data that's already been accessed.</p>
<p>A value of 0 indicates that no list items will be loaded until they are specifically requested. This is generally not recommended, so that users don't observe a placeholder item (with placeholders) or end of list (without) while scrolling.</p>
</div>
<h2>Public constructors</h2>
<div><a name="PagingConfig(kotlin.Int, kotlin.Int, kotlin.Boolean, kotlin.Int, kotlin.Int, kotlin.Int)"></a><a name="PagingConfig-kotlin.Int-kotlin.Int-kotlin.Boolean-kotlin.Int-kotlin.Int-kotlin.Int-"></a>
<h3 class="api-name" id="PagingConfig(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)">PagingConfig</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a><br>public&nbsp;final&nbsp;<a href="/reference/androidx/paging/PagingConfig.html#PagingConfig(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)">PagingConfig</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;int&nbsp;pageSize,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;@<a href="/reference/kotlin/ranges/IntRange.html">IntRange</a>&nbsp;int&nbsp;prefetchDistance,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;boolean&nbsp;enablePlaceholders,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;@<a href="/reference/kotlin/ranges/IntRange.html">IntRange</a>&nbsp;int&nbsp;initialLoadSize,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;@<a href="/reference/kotlin/ranges/IntRange.html">IntRange</a>&nbsp;int&nbsp;maxSize,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;int&nbsp;jumpThreshold<br>)</pre>
</div>
</body>
</html>