Skip to content

Instantly share code, notes, and snippets.

@wajahatkarim3
Created July 4, 2022 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wajahatkarim3/059baf1a4b3a279a0771630bcb8a0ee7 to your computer and use it in GitHub Desktop.
Save wajahatkarim3/059baf1a4b3a279a0771630bcb8a0ee7 to your computer and use it in GitHub Desktop.
// Get the DataStore object
private val settingsDataStore by preferencesDataStore(name = “app_settings”)
// Get the keys
val myStrKey = stringPreferencesKey("myStrKey")
// Read the values through coroutine scopes
lifecycleScope.launch {
settingsDataStore.data.map { pref ->
// Read the values here
val myStr = pref[myStrKey]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment