Law Gimenez
07/01/2021, 8:07 AMcreateDataStore
method not found. I already added the library on Gradle. I’m following Google’s documentation by the waypatrick
07/01/2021, 8:13 AMLaw Gimenez
07/01/2021, 8:20 AMpatrick
07/01/2021, 8:28 AMval Context.myDataStore by preferencesDataStore(
name = "settings",
produceMigrations = { context ->
listOf(
SharedPreferencesMigration(context, "settings")
)
}
)
?Law Gimenez
07/01/2021, 8:30 AMpatrick
07/01/2021, 8:33 AMval Context.myDataStore by preferencesDataStore(
name = "filename",
produceMigrations = { context ->
listOf(
SharedPreferencesMigration(context, "settings")
)
}
)
object OnlineJobPreferences{
fun save(context: Context, jobPreferences: String){
val dataStore = context.myDataStore
dataStore.updateData { ... }
}
}
You can access the datastore anywhere in your codebase by calling myDataStore
on a context and the migration should happen automaticallyLaw Gimenez
07/01/2021, 8:36 AMpatrick
07/01/2021, 8:37 AMLaw Gimenez
07/01/2021, 8:37 AM