blob: 4afb5c89375c1bd35646e30874d4e6e343d9ab40 [file] [log] [blame]
<html devsite="true">
<head>
<title>PagingLiveDataKt</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>PagingLiveDataKt</h1>
{% setvar page_path %}androidx/paging/PagingLiveDataKt.html{% endsetvar %}
{% setvar can_switch %}1{% endsetvar %}
{% include "reference/_java_switcher2.md" %}
<p>
<pre>public final class PagingLiveDataKt</pre>
</p>
<hr>
<h2>Summary</h2>
<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 <a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/androidx/paging/PagingData.html">PagingData</a>&lt;Value&gt;&gt;</code></td>
<td width="100%">
<div><code><a href="/reference/androidx/paging/package-summary.html#liveData(androidx.paging.Pager)">liveData</a></code></div>
<p>A LiveData of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code>, which mirrors the stream provided by <code><a href="/reference/androidx/paging/Pager.html#flow()">Pager.flow</a></code>, but exposes it as a LiveData.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>static&nbsp;final <a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a></code></td>
<td width="100%">
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/PagingLiveDataKt.html#cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;,Lifecycle)">cachedIn</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/androidx/paging/PagingData.html">PagingData</a>&lt;T&gt;&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;lifecycle<br>)</code></div>
<p>Operator which caches a LiveData of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> within the scope of a Lifecycle.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final <a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a></code></td>
<td width="100%">
<div><code>&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/PagingLiveDataKt.html#cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;,kotlinx.coroutines.CoroutineScope)">cachedIn</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/androidx/paging/PagingData.html">PagingData</a>&lt;T&gt;&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>&nbsp;scope<br>)</code></div>
<p>Operator which caches a LiveData of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> within a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>Public fields</h2>
<div><a name="getLiveData(androidx.paging.Pager)"></a><a name="setLiveData(androidx.paging.Pager)"></a><a name="getLiveData-androidx.paging.Pager-"></a><a name="setLiveData-androidx.paging.Pager-"></a>
<h3 class="api-name" id="liveData(androidx.paging.Pager)">liveData</h3>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/androidx/paging/PagingData.html">PagingData</a>&lt;Value&gt;&gt;&nbsp;<a href="/reference/androidx/paging/package-summary.html#liveData(androidx.paging.Pager)">liveData</a></pre>
<p>A <a href="[LiveData]">LiveData</a> of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code>, which mirrors the stream provided by <code><a href="/reference/androidx/paging/Pager.html#flow()">Pager.flow</a></code>, but exposes it as a <a href="[LiveData]">LiveData</a>.</p>
</div>
<h2>Public methods</h2>
<div><a name="cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;, Lifecycle)"></a><a name="cachedIn-LiveData&lt;PagingData&lt;T&gt;&gt;-Lifecycle-"></a>
<h3 class="api-name" id="cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;,Lifecycle)">cachedIn</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/PagingLiveDataKt.html#cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;,Lifecycle)">cachedIn</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/androidx/paging/PagingData.html">PagingData</a>&lt;T&gt;&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;lifecycle<br>)</pre>
<p>Operator which caches a <a href="[LiveData]">LiveData</a> of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> within the scope of a <a href="[Lifecycle]">Lifecycle</a>.</p>
<p><code><a href="/reference/androidx/paging/package-summary.html#cachedIn(kotlinx.coroutines.flow.Flow,kotlinx.coroutines.CoroutineScope)">cachedIn</a></code> multicasts pages loaded and transformed by a <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code>, allowing multiple observers on the same instance of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> to receive the same events, avoiding redundant work, but comes at the cost of buffering those events in memory.</p>
<p>Calling <code><a href="/reference/androidx/paging/package-summary.html#cachedIn(kotlinx.coroutines.flow.Flow,kotlinx.coroutines.CoroutineScope)">cachedIn</a></code> is required to allow calling <a href="[androidx.paging.AsyncPagingDataAdapter]">androidx.paging.AsyncPagingDataAdapter</a> on the same instance of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> emitted by <code><a href="/reference/androidx/paging/Pager.html">Pager</a></code> or any of its transformed derivatives, as reloading data from scratch on the same generation of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> is an unsupported operation.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;lifecycle</code></td>
<td width="100%">
<p>The <a href="[Lifecycle]">Lifecycle</a> where the page cache will be kept alive.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><a name="cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;, kotlinx.coroutines.CoroutineScope)"></a><a name="cachedIn-LiveData&lt;PagingData&lt;T&gt;&gt;-kotlinx.coroutines.CoroutineScope-"></a>
<h3 class="api-name" id="cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;,kotlinx.coroutines.CoroutineScope)">cachedIn</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/paging/PagingLiveDataKt.html#cachedIn(LiveData&lt;PagingData&lt;T&gt;&gt;,kotlinx.coroutines.CoroutineScope)">cachedIn</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/[JVM root]/&lt;ERROR CLASS&gt;.html">&lt;ERROR CLASS&gt;</a>&lt;<a href="/reference/androidx/paging/PagingData.html">PagingData</a>&lt;T&gt;&gt;&nbsp;receiver,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>&nbsp;scope<br>)</pre>
<p>Operator which caches a <a href="[LiveData]">LiveData</a> of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> within a <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code>.</p>
<p><code><a href="/reference/androidx/paging/package-summary.html#cachedIn(kotlinx.coroutines.flow.Flow,kotlinx.coroutines.CoroutineScope)">cachedIn</a></code> multicasts pages loaded and transformed by a <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code>, allowing multiple observers on the same instance of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> to receive the same events, avoiding redundant work, but comes at the cost of buffering those events in memory.</p>
<p>Calling <code><a href="/reference/androidx/paging/package-summary.html#cachedIn(kotlinx.coroutines.flow.Flow,kotlinx.coroutines.CoroutineScope)">cachedIn</a></code> is required to allow calling <a href="[androidx.paging.AsyncPagingDataAdapter]">androidx.paging.AsyncPagingDataAdapter</a> on the same instance of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> emitted by <code><a href="/reference/androidx/paging/Pager.html">Pager</a></code> or any of its transformed derivatives, as reloading data from scratch on the same generation of <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> is an unsupported operation.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2">Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>&nbsp;scope</code></td>
<td width="100%">
<p>The <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> where the page cache will be kept alive. Typically this would be a managed scope such as <code>ViewModel.viewModelScope</code>, which automatically cancels after the <code><a href="/reference/androidx/paging/PagingData.html">PagingData</a></code> stream is no longer needed. Otherwise, the provided <code><a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a></code> must be manually cancelled to avoid memory leaks.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>