Preferences DataStore
Store key-value settings reactively.
Preferences DataStore
Preferences DataStore stores simple key-value pairs, just like SharedPreferences, but with the modern async API. It does not enforce a schema or type-safety on the whole object.
You access values through typed keys.
Creating the DataStore
You create a single DataStore instance per file using the preferencesDataStore property delegate at the top level of a Kotlin file. The name becomes the on-disk filename.
import androidx.datastore.preferences.preferencesDataStore
import androidx.datastore.preferences.core.Preferences
val Context.dataStore: DataStore<Preferences> by
preferencesDataStore(name = "settings")All lessons in this course
- DataStore vs SharedPreferences
- Preferences DataStore
- Reading and Writing Settings
- Proto DataStore