Jetpack DataStore
Modern Android Jetpack replacement for SharedPreferences. DataStore provides two APIs: Preferences DataStore (key-value pairs, no schema) and Proto DataStore (typed Protocol Buffer schema, requires .proto file). Key advantages over SharedPreferences: Kotlin coroutines and Flow for async access (no blocking main thread), ACID transactions, handles exceptions properly (SharedPreferences silently swallows IOExceptions), and Kotlin DSL API. Part of Android Jetpack, recommended by Google for all new Android key-value storage.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
App sandbox protects DataStore file. No encryption by default — use EncryptedDataStore pattern for sensitive agent tokens. File stored in app's private storage. Proto DataStore provides schema validation vs arbitrary key-value.
⚡ Reliability
Best When
You're replacing SharedPreferences in an Android Kotlin app — DataStore's coroutine/Flow API prevents main thread blocking, and Proto DataStore adds type safety for complex settings.
Avoid When
You need relational data (use Room), you're in a multi-platform context (DataStore is Android-only), or your Java-only codebase makes DataStore's Kotlin API awkward.
Use Cases
- • Store agent user preferences (theme, notification settings, API key) using Preferences DataStore — coroutine-based access prevents ANR from blocking main thread
- • Persist typed agent configuration using Proto DataStore — structured proto schema enforces type safety for agent settings vs string-keyed Preferences DataStore
- • React to agent preference changes using DataStore's Flow — dataStore.data.map { preferences -> preferences[AGENT_MODE] } emits updates as Flow for reactive UI
- • Replace SharedPreferences in agent Android apps — DataStore.updateData { } provides atomic updates; no more apply()/commit() confusion from SharedPreferences
- • Store agent authentication tokens using EncryptedDataStore — combine Jetpack DataStore with encrypted file for secure agent credential storage
Not For
- • Large datasets or complex queries — DataStore is for simple key-value settings; use Room for structured data with query needs
- • Server-side Kotlin or Kotlin Multiplatform (non-Android) — DataStore is Android-only; use DataStore only in Android modules
- • Legacy Java code — DataStore's coroutine API doesn't work well with Java; migrate to Kotlin before adopting DataStore, or keep SharedPreferences for Java-based components
Interface
Authentication
Local storage library — no auth concepts. Use EncryptedDataStore (custom wrapper with SQLCipher) for sensitive agent data like tokens.
Pricing
Jetpack DataStore is Apache 2.0 licensed, maintained by Google. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ One DataStore instance per file — creating multiple DataStore instances pointing to the same file causes data corruption; use singleton pattern via Kotlin delegate or Hilt; multiple instances are a common migration mistake from SharedPreferences
- ⚠ DataStore is not a drop-in SharedPreferences replacement — DataStore API is async (suspend/Flow); code that called SharedPreferences.getString() synchronously must be refactored to suspend functions or collectAsState() in Compose
- ⚠ Proto DataStore requires .proto file and code generation — protobuf schema must be defined in src/main/proto/*.proto and protobuf Gradle plugin generates Kotlin classes; build setup more complex than Preferences DataStore
- ⚠ Migration from SharedPreferences — use SharedPreferencesMigration in DataStore builder to migrate existing SP data; without migration, SP data is lost and users see default values on first DataStore use
- ⚠ Coroutine scope for DataStore operations — dataStore.updateData { } is a suspend function requiring coroutine scope; calling from non-coroutine context (ViewModel init, BroadcastReceiver) requires runBlocking or scope.launch carefully
- ⚠ DataStore.data Flow emits on every preferences change — subscribing to dataStore.data emits on any key change in the file, not just the specific key watched; use .map { it[key] }.distinctUntilChanged() to filter to specific key changes
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for Jetpack DataStore.
Scores are editorial opinions as of 2026-03-06.