# SharedPreferencesMigrationKt

Added in 1.0.0

*** ** * ** ***


```
public final class SharedPreferencesMigrationKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/migrations/SharedPreferencesMigration<@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/SharedPreferencesMigrationKt#SharedPreferencesMigration(kotlin.Function0,kotlin.collections.Set)( @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/SharedPreferences.html> produceSharedPreferences, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> keysToMigrate )` Creates a SharedPreferencesMigration for DataStore . <br /> |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/migrations/SharedPreferencesMigration<@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/SharedPreferencesMigrationKt#SharedPreferencesMigration(android.content.Context,kotlin.String,kotlin.collections.Set)( @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 sharedPreferencesName, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> keysToMigrate )` Creates a SharedPreferencesMigration for DataStore. |

## Public methods

### SharedPreferencesMigration

Artifact: [androidx.datastore:datastore-preferences](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/preferences/SharedPreferencesMigration.android.kt+function:SharedPreferencesMigration)

```
public static final @NonNull SharedPreferencesMigration<@NonNull Preferences> SharedPreferencesMigration(
    @NonNull Function0<@NonNull SharedPreferences> produceSharedPreferences,
    @NonNull Set<@NonNull String> keysToMigrate
)
```

Creates a SharedPreferencesMigration for DataStore
.

<br />

Note: This migration only supports the basic SharedPreferences types: boolean, float, int, long, string and string set. If the result of getAll contains other types, they will be ignored.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/SharedPreferences.html> produceSharedPreferences` | Should return the instance of SharedPreferences to migrate from. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> keysToMigrate` | The list of keys to migrate. The keys will be mapped to datastore.Preferences with their same values. If the key is already present in the new Preferences, the key will not be migrated again. If the key is not present in the SharedPreferences it will not be migrated. If keysToMigrate is not set, all keys will be migrated from the existing SharedPreferences. |

### SharedPreferencesMigration

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

```
public static final @NonNull SharedPreferencesMigration<@NonNull Preferences> SharedPreferencesMigration(
    @NonNull Context context,
    @NonNull String sharedPreferencesName,
    @NonNull Set<@NonNull String> keysToMigrate
)
```

Creates a SharedPreferencesMigration for DataStore.

If the SharedPreferences is empty once the migration completes, this migration will attempt to delete it.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | Context used for getting SharedPreferences. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sharedPreferencesName` | The name of the SharedPreferences. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> keysToMigrate` | The list of keys to migrate. The keys will be mapped to datastore.Preferences with their same values. If the key is already present in the new Preferences, the key will not be migrated again. If the key is not present in the SharedPreferences it will not be migrated. If keysToMigrate is not set, all keys will be migrated from the existing SharedPreferences. |