# RxSharedPreferencesMigration

# RxSharedPreferencesMigration

Artifact:[androidx.datastore:datastore-rxjava2](https://developer.android.com/jetpack/androidx/releases/datastore)  
[View Source](https://cs.android.com/search?q=file:androidx/datastore/rxjava2/RxSharedPreferencesMigration.kt+class:androidx.datastore.rxjava2.RxSharedPreferencesMigration)  
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/rxjava2/RxSharedPreferencesMigration "View this page in Java")

<br />

```
interface RxSharedPreferencesMigration<T : Any?>
```

<br />

*** ** * ** ***

Client implemented migration interface.

## Summary

|                                                                            ### Public functions                                                                            |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Single](https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html)`<T>`                                                                                            | [migrate](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxSharedPreferencesMigration#migrate([Error type: Unresolved type for SharedPreferencesView],kotlin.Any))`(` ` sharedPreferencesView: `[<Error class: unknown class>](https://developer.android.com/reference/kotlin/[JVM root]/<Error class: unknown class>)`,` ` currentData: T` `)` Maps SharedPreferences into T. |
| `open `[Single](https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html)`<`[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`>` | [shouldMigrate](https://developer.android.com/reference/kotlin/androidx/datastore/rxjava2/RxSharedPreferencesMigration#shouldMigrate(kotlin.Any))`(currentData: T)` Whether or not the migration should be run.                                                                                                                                                                                           |

## Public functions

### migrate

```
fun migrate(
    sharedPreferencesView: <Error class: unknown class>,
    currentData: T
): Single<T>
```

Maps SharedPreferences into T. Implementations should be idempotent since this may be called multiple times. See[DataMigration.migrate](https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration#migrate(kotlin.Any))for more information. The method accepts a SharedPreferencesView which is the view of the SharedPreferences to migrate from (limited to keysToMigrate and a T which represent the current data. The function must return the migrated data.

If SharedPreferences is empty or does not contain any keys which you specified, this callback will not run.  

|                                                                   Parameters                                                                    |
|-------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| `sharedPreferencesView: `[<Error class: unknown class>](https://developer.android.com/reference/kotlin/[JVM root]/<Error class: unknown class>) | the current state of the SharedPreferences |
| `currentData: T`                                                                                                                                | the most recently persisted data           |

|                                     Returns                                     |
|---------------------------------------------------------------------------------|------------------------------|
| [Single](https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html)`<T>` | a Single of the updated data |

### shouldMigrate

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

```
open fun shouldMigrate(currentData: T): Single<Boolean>
```

Whether or not the migration should be run. This can be used to skip a read from the SharedPreferences.  

|    Parameters    |
|------------------|----------------------------------|
| `currentData: T` | the most recently persisted data |

|                                                                               Returns                                                                               |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [Single](https://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Single.html)`<`[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`>` | a Single indicating whether or not the migration should be run. |