# RxPreferenceDataStoreBuilder

Artifact: [androidx.datastore:datastore-preferences-rxjava3](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder.kt+class:androidx.datastore.preferences.rxjava3.RxPreferenceDataStoreBuilder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

*** ** * ** ***


```
public final class RxPreferenceDataStoreBuilder
```

<br />

*** ** * ** ***

Builder for a Preferences RxDataStore that works on a single process.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder#RxPreferenceDataStoreBuilder(java.util.concurrent.Callable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html> produceFile)` Create a RxPreferenceDataStoreBuilder with the callable which returns the File that DataStore acts on. |
| `https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder#RxPreferenceDataStoreBuilder(android.content.Context,kotlin.String)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html name )` Create a RxPreferenceDataStoreBuilder with the Context and name from which to derive the DataStore file. |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | `https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder#addDataMigration(androidx.datastore.core.DataMigration)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/DataMigration<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences> dataMigration )` Add a DataMigration to the Datastore. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | `https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder#addRxDataMigration(androidx.datastore.rxjava3.RxDataMigration)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/rxjava3/RxDataMigration<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences> rxDataMigration )` Add an RxDataMigration to the DataStore. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/rxjava3/RxDataStore<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences>` | `https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder#build()()` Build the DataStore. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | `https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder#setCorruptionHandler(androidx.datastore.core.handlers.ReplaceFileCorruptionHandler)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences> corruptionHandler )` Sets the corruption handler to install into the DataStore. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | `https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder#setIoScheduler(io.reactivex.rxjava3.core.Scheduler)(@https://developer.android.com/reference/androidx/annotation/NonNull http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Scheduler.html ioScheduler)` Set the Scheduler on which to perform IO and transform operations. |

## Public constructors

### RxPreferenceDataStoreBuilder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

```
public RxPreferenceDataStoreBuilder(@NonNull Callable<@NonNull File> produceFile)
```

Create a RxPreferenceDataStoreBuilder with the callable which returns the File that DataStore acts on. The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html> produceFile` | 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. |

### RxPreferenceDataStoreBuilder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

```
public RxPreferenceDataStoreBuilder(
    @NonNull Context context,
    @NonNull String name
)
```

Create a RxPreferenceDataStoreBuilder with the Context and name from which to derive the DataStore file. The file is generated by calling File(context.filesDir, "datastore/" + name + ".preferences_pb"). The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the context from which we retrieve files directory. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html name` | the filename relative to Context.filesDir that DataStore acts on. The File is obtained by calling File(this.filesDir, "datastore/$name.preferences_pb"). No two instances of DataStore should act on the same file at the same time. |

## Public methods

### addDataMigration

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

```
public final @NonNull RxPreferenceDataStoreBuilder addDataMigration(
    @NonNull DataMigration<@NonNull Preferences> dataMigration
)
```

Add a DataMigration to the Datastore. Migrations are run in the order they are added.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/DataMigration<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences> dataMigration` | the migration to add |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | this |

### addRxDataMigration

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

```
public final @NonNull RxPreferenceDataStoreBuilder addRxDataMigration(
    @NonNull RxDataMigration<@NonNull Preferences> rxDataMigration
)
```

Add an RxDataMigration to the DataStore. Migrations are run in the order they are added.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/rxjava3/RxDataMigration<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences> rxDataMigration` | the migration to add. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | this |

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

```
public final @NonNull RxDataStore<@NonNull Preferences> build()
```

Build the DataStore.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/rxjava3/RxDataStore<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences>` | the DataStore with the provided parameters |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if serializer is not set or if neither produceFile not context and name are set. |

### setCorruptionHandler

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

```
public final @NonNull RxPreferenceDataStoreBuilder setCorruptionHandler(
    @NonNull ReplaceFileCorruptionHandler<@NonNull Preferences> corruptionHandler
)
```

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/core/Preferences> corruptionHandler` | the ReplaceFileCorruptionHandler to install |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | this |

### setIoScheduler

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.0.0)

```
public final @NonNull RxPreferenceDataStoreBuilder setIoScheduler(@NonNull Scheduler ioScheduler)
```

Set the Scheduler on which to perform IO and transform operations. This is converted into a CoroutineDispatcher before being added to DataStore.

This parameter is optional and defaults to Schedulers.io().

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Scheduler.html ioScheduler` | the scheduler on which IO and transform operations are run |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/preferences/rxjava3/RxPreferenceDataStoreBuilder` | this |