Skip to content
Commitwise
Menu

DataStore

Jetpack's replacement for SharedPreferences: data is read as a Flow and written in atomic, asynchronous transactions.

Definition

Preferences DataStore stores key-value pairs; typed (Proto) DataStore stores one serializable object. There must be exactly one instance per file, reads never block the main thread, and updates happen inside edit or updateData so concurrent changes don't overwrite each other.

In practice

The settings repository exposes Flow<Settings>, and toggling dark mode calls store.edit { it[DarkMode] = true }.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.