partially migrate dynamic SharedPreference keys to datastore

Viewed 28

I am trying to migrate from shared preference to jetpack datastore. While creating the datastore object we need to pass shared preference keys to migrate however if the keys are build based on usecases like dynamic strings and if we dont want to migrate all the keys at same time. Is it possible to create the datastore object and notify them later the key to migrate?

val datastore = PreferenceDataStoreFactory.create(
                corruptionHandler = ReplaceFileCorruptionHandler(
                    produceNewData = { emptyPreferences() }
                ),
   //SharedPreferenceMigration object with list of keys to migrate.
           //  dont know keys at this point of time in app.
                migrations = listOf(), 
                scope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
                produceFile = {
                    context.preferencesDataStoreFile(
                        "datastore file name"
                    )
                }
            ) 
0 Answers
Related