Reading and Writing Settings
Save and observe user preferences.
Reading and Writing
With keys defined, the two core operations are reading the data flow and writing with edit. Reads are reactive, writes are suspend functions.
The data Flow
dataStore.data is a Flow<Preferences>. Every time you write, the flow emits a fresh Preferences snapshot, so collectors stay up to date automatically.
val rawData: Flow<Preferences> = dataStore.dataAll lessons in this course
- DataStore vs SharedPreferences
- Preferences DataStore
- Reading and Writing Settings
- Proto DataStore