Dependency : implementation "androidx.datastore:datastore-preferences:1.0.0"
Preferences DataStore uses key-value pairs to store smaller datasets, without defining the schema upfront. This might remind you of SharedPreferences, but only in the way it structures your data models. There are a variety of benefits brought by DataStore over its SharedPreferences predecessor.
Provides a fully asynchronous API for retrieving and saving data, using the power of Kotlin coroutines
Does not offer ready-to-use synchronous support — it directly avoids doing any work that blocks the UI thread
Relies on Flow’s inner error signaling mechanism, allowing you to safely catch and handle exceptions when reading or writing data
Handles data updates transactionally in an atomic read-modify-write operation, providing strong ACID guarantees
Allows easy and quick data migrations
Wish to quickly migrate from SharedPreferences with minimal changes and feel confident enough without full type safety? Choose Preferences over Proto.
#androidappdevelopment #android #androidapp
#preferences #datastore #kotlin