Trung BìnhAndroid iconAndroid

DataStore là gì và khác SharedPreferences như thế nào?

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.

Xem toàn bộ Android cùng filter theo level & chủ đề con.

Mở danh sách Android