DataStore là sự thay thế hiện đại cho SharedPreferences, được xây dựng trên coroutine và Flow cho lưu trữ dữ liệu type-safe và transactional.
- Async-first (không blocking), hỗ trợ protocol buffer cho type safety, và an toàn hơn SharedPreferences vốn có vấn đề threading.
- Dùng
context.dataStore.data.map { it.setting }để đọc vàcontext.dataStore.updateData { it.copy(setting = value) }để ghi.