# RxSharedPreferencesMigration

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

*** ** * ** ***


```
public interface RxSharedPreferencesMigration<T extends Object>
```

<br />

*** ** * ** ***

Client implemented migration interface.

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/datastore/rxjava3/RxSharedPreferencesMigration#migrate(androidx.datastore.migrations.SharedPreferencesView,kotlin.Any)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/migrations/SharedPreferencesView sharedPreferencesView, @https://developer.android.com/reference/androidx/annotation/NonNull T currentData )` Maps SharedPreferences into T. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html>` | `https://developer.android.com/reference/androidx/datastore/rxjava3/RxSharedPreferencesMigration#shouldMigrate(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull T currentData)` Whether or not the migration should be run. |

## Public methods

### migrate

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

```
abstract @NonNull Single<@NonNull T> migrate(
    @NonNull SharedPreferencesView sharedPreferencesView,
    @NonNull T currentData
)
```

Maps SharedPreferences into T. Implementations should be idempotent since this may be called multiple times. See `https://developer.android.com/reference/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 `https://developer.android.com/reference/androidx/datastore/rxjava3/RxSharedPreferencesMigrationBuilder#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/migrations/SharedPreferencesView sharedPreferencesView` | the current state of the SharedPreferences |
| `@https://developer.android.com/reference/androidx/annotation/NonNull T currentData` | the most recently persisted data |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | a Single of the updated data |

### shouldMigrate

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

```
default @NonNull Single<@NonNull Boolean> shouldMigrate(@NonNull T currentData)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T currentData` | the most recently persisted data |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html>` | a Single indicating whether or not the migration should be run. |