# RxPreferenceDataStoreBuilder

# RxPreferenceDataStoreBuilder

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder "View this page in Java")

<br />

```
class RxPreferenceDataStoreBuilder
```

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                                                                                                                                                 ### Public constructors                                                                                                                                                                                                                                                  |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder#RxPreferenceDataStoreBuilder(java.util.concurrent.Callable))`(produceFile: `[Callable](https://developer.android.com/reference/java/util/concurrent/Callable.html)`<`[File](https://developer.android.com/reference/java/io/File.html)`>)` Create a RxPreferenceDataStoreBuilder with the callable which returns the File that DataStore acts on.                      |
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder#RxPreferenceDataStoreBuilder(android.content.Context,kotlin.String))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, name: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Create a RxPreferenceDataStoreBuilder with the Context and name from which to derive the DataStore file. |

|                                                                                                  ### Public functions                                                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder)                                                                      | [addDataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder#addDataMigration(androidx.datastore.core.DataMigration))`(dataMigration: `[DataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>)` Add a DataMigration to the Datastore.                                                                                                        |
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder)                                                                      | [addRxDataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder#addRxDataMigration(androidx.datastore.rxjava2.RxDataMigration))`(rxDataMigration: `[RxDataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxDataMigration)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>)` Add an RxDataMigration to the DataStore.                                                                                   |
| [RxDataStore](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxDataStore)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>` | [build](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder#build())`()` Build the DataStore.                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder)                                                                      | [setCorruptionHandler](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder#setCorruptionHandler(androidx.datastore.core.handlers.ReplaceFileCorruptionHandler))`(` ` corruptionHandler: `[ReplaceFileCorruptionHandler](https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>` `)` Sets the corruption handler to install into the DataStore. |
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder)                                                                      | [setIoScheduler](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder#setIoScheduler(io.reactivex.Scheduler))`(ioScheduler: `[Scheduler](https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Scheduler.html)`)` 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)  

```
RxPreferenceDataStoreBuilder(produceFile: Callable<File>)
```

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                                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `produceFile: `[Callable](https://developer.android.com/reference/java/util/concurrent/Callable.html)`<`[File](https://developer.android.com/reference/java/io/File.html)`>` | 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)  

```
RxPreferenceDataStoreBuilder(context: Context, name: String)
```

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                                         |
|--------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | the context from which we retrieve files directory.                                                                                                                                                                                  |
| `name: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)  | 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 functions

### addDataMigration

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

```
fun addDataMigration(dataMigration: DataMigration<Preferences>): RxPreferenceDataStoreBuilder
```

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

|                                                                                                                Parameters                                                                                                                 |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
| `dataMigration: `[DataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>` | the migration to add |

|                                                                      Returns                                                                       |
|----------------------------------------------------------------------------------------------------------------------------------------------------|------|
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder) | this |

### addRxDataMigration

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

```
fun addRxDataMigration(rxDataMigration: RxDataMigration<Preferences>): RxPreferenceDataStoreBuilder
```

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

|                                                                                                                     Parameters                                                                                                                     |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|
| `rxDataMigration: `[RxDataMigration](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxDataMigration)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>` | the migration to add. |

|                                                                      Returns                                                                       |
|----------------------------------------------------------------------------------------------------------------------------------------------------|------|
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder) | this |

### build

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

```
fun build(): RxDataStore<Preferences>
```

Build the DataStore.  

|                                                                                                         Returns                                                                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| [RxDataStore](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxDataStore)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>` | the DataStore with the provided parameters |

|                                                          Throws                                                          |
|--------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
| [kotlin.IllegalStateException](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)  

```
fun setCorruptionHandler(
    corruptionHandler: ReplaceFileCorruptionHandler<Preferences>
): RxPreferenceDataStoreBuilder
```

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.  

|                                                                                                                                      Parameters                                                                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|
| `corruptionHandler: `[ReplaceFileCorruptionHandler](https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler)`<`[Preferences](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences)`>` | the ReplaceFileCorruptionHandler to install |

|                                                                      Returns                                                                       |
|----------------------------------------------------------------------------------------------------------------------------------------------------|------|
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder) | this |

### setIoScheduler

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

```
fun setIoScheduler(ioScheduler: Scheduler): RxPreferenceDataStoreBuilder
```

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                                            |
|-------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| `ioScheduler: `[Scheduler](https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Scheduler.html) | the scheduler on which IO and transform operations are run |

|                                                                      Returns                                                                       |
|----------------------------------------------------------------------------------------------------------------------------------------------------|------|
| [RxPreferenceDataStoreBuilder](https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder) | this |