blob: a98ef96068ef3c213a70a579954d6bf07d3d7b2e [file] [log] [blame]
<html devsite="true">
<head>
<title>DataStoreFactory</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div id="metadata-info-block">
<div id="source-link"><a href="https://cs.android.com/search?q=file:androidx/datastore/core/DataStoreFactory.+class:androidx.datastore.core.DataStoreFactory&amp;ss=androidx/platform/frameworks/support" class="external">View Source</a></div>
</div>
<h1>DataStoreFactory</h1>
<p>
<pre>public static class <a href="/reference/androidx/datastore/core/DataStoreFactory.html">DataStoreFactory</a></pre>
</p>
<hr>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public fields</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>static @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataStoreFactory.html">DataStoreFactory</a></code></td>
<td>
<div><code><a href="/reference/androidx/datastore/core/DataStoreFactory.html#INSTANCE()">INSTANCE</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><code>static&nbsp;final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataStore.html">DataStore</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;</code></td>
<td>
<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/datastore/core/DataStoreFactory.html#create(androidx.datastore.core.Storage,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.collections.List,[Error type: Unresolved type for CoroutineScope])">create</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/Storage.html">Storage</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;storage,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html">ReplaceFileCorruptionHandler</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;corruptionHandler,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/List.html">List</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataMigration.html">DataMigration</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&gt;&nbsp;migrations,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/[JVM root]/&lt;Error class: unknown class&gt;.html">&lt;Error class: unknown class&gt;</a>&nbsp;scope<br>)</code></div>
</td>
</tr>
<tr>
<td><code>static&nbsp;final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataStore.html">DataStore</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;</code></td>
<td>
<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/datastore/core/DataStoreFactory.html#create(androidx.datastore.core.Serializer,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.collections.List,kotlinx.coroutines.CoroutineScope,kotlin.Function0)">create</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/Serializer.html">Serializer</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;serializer,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html">ReplaceFileCorruptionHandler</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;corruptionHandler,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/List.html">List</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataMigration.html">DataMigration</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&gt;&nbsp;migrations,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>&nbsp;scope,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/io/File.html">File</a>&gt;&nbsp;produceFile<br>)</code></div>
<p>Create an instance of SingleProcessDataStore.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public fields</h2>
<div class="api-item"><a name="getINSTANCE()"></a><a name="setINSTANCE()"></a><a name="getINSTANCE--"></a><a name="setINSTANCE--"></a>
<h3 class="api-name" id="INSTANCE()">INSTANCE</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataStoreFactory.html">DataStoreFactory</a>&nbsp;<a href="/reference/androidx/datastore/core/DataStoreFactory.html#INSTANCE()">INSTANCE</a></pre>
</div>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="create(androidx.datastore.core.Storage, androidx.datastore.core.handlers.ReplaceFileCorruptionHandler, kotlin.collections.List, [Error type: Unresolved type for CoroutineScope])"></a><a name="create-androidx.datastore.core.Storage-androidx.datastore.core.handlers.ReplaceFileCorruptionHandler-kotlin.collections.List-[Error type: Unresolved type for CoroutineScope]-"></a><a name="create"></a>
<h3 class="api-name" id="create(androidx.datastore.core.Storage,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.collections.List,[Error type: Unresolved type for CoroutineScope])">create</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataStore.html">DataStore</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/datastore/core/DataStoreFactory.html#create(androidx.datastore.core.Storage,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.collections.List,[Error type: Unresolved type for CoroutineScope])">create</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/Storage.html">Storage</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;storage,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html">ReplaceFileCorruptionHandler</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;corruptionHandler,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/List.html">List</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataMigration.html">DataMigration</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&gt;&nbsp;migrations,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/[JVM root]/&lt;Error class: unknown class&gt;.html">&lt;Error class: unknown class&gt;</a>&nbsp;scope<br>)</pre>
</div>
<div class="api-item"><a name="create(androidx.datastore.core.Serializer, androidx.datastore.core.handlers.ReplaceFileCorruptionHandler, kotlin.collections.List, kotlinx.coroutines.CoroutineScope, kotlin.Function0)"></a><a name="create-androidx.datastore.core.Serializer-androidx.datastore.core.handlers.ReplaceFileCorruptionHandler-kotlin.collections.List-kotlinx.coroutines.CoroutineScope-kotlin.Function0-"></a><a name="create"></a>
<h3 class="api-name" id="create(androidx.datastore.core.Serializer,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.collections.List,kotlinx.coroutines.CoroutineScope,kotlin.Function0)">create</h3>
<pre class="api-signature no-pretty-print">public&nbsp;static&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataStore.html">DataStore</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;&lt;T&nbsp;extends&nbsp;<a href="https://developer.android.com/reference/java/lang/Object.html">Object</a>&gt; <a href="/reference/androidx/datastore/core/DataStoreFactory.html#create(androidx.datastore.core.Serializer,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.collections.List,kotlinx.coroutines.CoroutineScope,kotlin.Function0)">create</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/Serializer.html">Serializer</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;serializer,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html">ReplaceFileCorruptionHandler</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;corruptionHandler,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/List.html">List</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataMigration.html">DataMigration</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&gt;&nbsp;migrations,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>&nbsp;scope,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/io/File.html">File</a>&gt;&nbsp;produceFile<br>)</pre>
<p>Create an instance of SingleProcessDataStore. Never create more than one instance of DataStore for a given file; doing so can break all DataStore functionality. You should consider managing your DataStore instance as a singleton. If there are multiple DataStores active, DataStore will throw IllegalStateException when reading or updating data. A DataStore is considered active as long as its scope is active.</p>
<p>T is the type DataStore acts on. The type T must be immutable. Mutating a type used in DataStore invalidates any guarantees that DataStore provides and will result in potentially serious, hard-to-catch bugs. We strongly recommend using protocol buffers: https://developers.google.com/protocol-buffers/docs/javatutorial - which provides immutability guarantees, a simple API and efficient serialization.</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><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/Serializer.html">Serializer</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;serializer</code></td>
<td>
<p>Serializer for the type T used with DataStore. The type T must be immutable.</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler.html">ReplaceFileCorruptionHandler</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&nbsp;corruptionHandler</code></td>
<td>
<p>The corruptionHandler is invoked if DataStore encounters a <code><a href="/reference/androidx/datastore/core/CorruptionException.html">CorruptionException</a></code> when attempting to read data. CorruptionExceptions are thrown by serializers when data can not be de-serialized.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/util/List.html">List</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataMigration.html">DataMigration</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;&gt;&nbsp;migrations</code></td>
<td>
<p>Migrations are run before any access to data can occur. Migrations must be idempotent.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html">CoroutineScope</a>&nbsp;scope</code></td>
<td>
<p>The scope in which IO operations and transform functions will execute.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> Function0&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/io/File.html">File</a>&gt;&nbsp;produceFile</code></td>
<td>
<p>Function which returns the file that the new DataStore will act on. The function must return the same path every time. No two instances of DataStore should act on the same file at the same time.</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><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/datastore/core/DataStore.html">DataStore</a>&lt;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> T&gt;</code></td>
<td>
<p>a new DataStore instance with the provided configuration</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>