0Pricing
Android Academy · Lesson

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.data

All lessons in this course

  1. DataStore vs SharedPreferences
  2. Preferences DataStore
  3. Reading and Writing Settings
  4. Proto DataStore
← Back to Android Academy