Handling data migration with DataStore
If you have built Android applications before, you might have used SharedPreferences
; the good news now is that there is support for migration, and you can migrate from SharedPreferences
to DataStore using SharedPreferenceMigration
. As with any data, we will always modify our dataset; for instance, we might want to rename our data model values or even change their type.
In such a scenario, we will need a DataStore to DataStore migration; that is what we will be working on in this recipe. The process is pretty similar to the migration from SharedPreferences
; as a matter of fact, SharedPreferencesMigration
is an implementation of the DataMigration
interface class.
Getting ready
Since we just created a new PreferenceDataStore
, we will not need to migrate it, but we can look at ways to implement a migration in case a need arises.
How to do it…
In this recipe, we will look at how you can utilize the knowledge learned to help you...