# androidx.datastore.preferences.rxjava2

*** ** * ** ***

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/RxPreferenceDataStoreBuilder` | Builder for a Preferences RxDataStore that works on a single process. |

## Top-level functions summary

|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.properties/-read-only-property/index.html<https://developer.android.com/reference/android/content/Context.html, https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxDataStore<https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences>>` | `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/rxjava2/package-summary#rxPreferencesDataStore(kotlin.String,androidx.datastore.core.handlers.ReplaceFileCorruptionHandler,kotlin.Function1,io.reactivex.Scheduler)( name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, corruptionHandler: https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler<https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences>?, produceMigrations: (https://developer.android.com/reference/android/content/Context.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration<https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences>>, scheduler: https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Scheduler.html )` Creates a property delegate for a single process Preferences DataStore. |

## Top-level functions

### rxPreferencesDataStore

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/RxPreferenceDataStoreDelegate.kt+function:rxPreferencesDataStore)

```
fun rxPreferencesDataStore(
    name: String,
    corruptionHandler: ReplaceFileCorruptionHandler<Preferences>? = null,
    produceMigrations: (Context) -> List<DataMigration<Preferences>> = { listOf() },
    scheduler: Scheduler = Schedulers.io()
): ReadOnlyProperty<Context, RxDataStore<Preferences>>
```

Creates a property delegate for a single process Preferences DataStore. This should only be called once in a file (at the top level), and all usages of the DataStore should use a reference the same Instance. The receiver type for the property delegate must be an instance of `https://developer.android.com/reference/android/content/Context.html`.

This should only be used from a single application in a single classloader in a single process.

Example usage:

```kotlin
val Context.myRxDataStore by rxPreferencesDataStore("filename", serializer)

class SomeClass(val context: Context) {
   fun update(): Single<Preferences> = context.myRxDataStore.updateDataAsync {...}
}
```

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the preferences. The preferences will be stored in a file in the "datastore/" subdirectory in the application context's files directory and is generated using `https://developer.android.com/reference/kotlin/androidx/datastore/preferences/package-summary#(android.content.Context).preferencesDataStoreFile(kotlin.String)`. |
| `corruptionHandler: https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReplaceFileCorruptionHandler<https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences>? = null` | The corruptionHandler is invoked if DataStore encounters a `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionException` when attempting to read data. CorruptionExceptions are thrown by serializers when data can not be de-serialized. |
| `produceMigrations: (https://developer.android.com/reference/android/content/Context.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration<https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences>> = { listOf() }` | produce the migrations. The ApplicationContext is passed in to these callbacks as a parameter. DataMigrations are run before any access to data can occur. Each producer and migration may be run more than once whether or not it already succeeded (potentially because another migration failed or a write to disk failed.) |
| `scheduler: https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Scheduler.html = Schedulers.io()` | The scope in which IO operations and transform functions will execute. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.properties/-read-only-property/index.html<https://developer.android.com/reference/android/content/Context.html, https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxDataStore<https://developer.android.com/reference/kotlin/androidx/datastore/preferences/core/Preferences>>` | a property delegate that manages a datastore as a singleton. |