DataStore Preferences and migrating from SharedPreferences
summary
DataStore replaces SharedPreferences for small key/value needs, using Kotlin coroutines and Flow on Dispatchers.IO to avoid UI blocking, and signals IO errors instead of failing silently. Two implementations exist: Proto DataStore (typed via protocol buffers, schema in app/src/main/proto, file like settings.pb, serializer + builder API) and Preference DataStore (simple key/value). A provided shared preferences migration helper and customizable mapper move legacy keys into the new store; production migrations report seamless results when mapper code is correct. Version noted: data-store-core 1.0.0.
AI-written summary · about
chapters (14)
- 0:00Introduction and agenda
- 1:51Why replace SharedPreferences
- 5:04DataStore benefits overview
- 8:42Setting up DataStore
- 10:26Preference DataStore basics
- 12:55Proto DataStore setup
- 13:39Defining Proto schema
- 16:16Proto DataStore operations
- 19:21Migrating from SharedPreferences
- 22:36Simple key-value migration
- 24:00Proto DataStore migration
- 27:12Synchronous access methods
- 28:58Summary and future outlook
- 30:21Q&A
related talks
27mSharing my preference for DataStore
19mJetpack DataStore - protocol buffers storage solution
26mSafely Migrating to DataStore in Production
25mThe New Modern Data Persistence on Android - Meet Jetpack Datastore
34mStoring app data reliably & performantly with SimpleStore
24mLightweight Realtime & Offline Data Storage on Android without a Database
06mCreate offline-first apps
26mWhats new with Data Storage?
