The android Jetpack team recently released the DataStore library (still in alpha) as a way of saving simple data using two implementations:
Rather than use DataStore, why don't we use sharedPreferences for simple datatypes and Room for more complex storage.
What are the BENEFITS OF USING DATASTORE IN ANDROID OVER USING SHAREDPREFERNCES (for simple data) + ROOM (for complex data).
DataStore is a new and improved data storage solution aimed at replacing SharedPreferences. Built on Kotlin coroutines and Flow, DataStore provides two different implementations: Proto DataStore, that stores typed objects (backed by protocol buffers) and Preferences DataStore, that stores key-value pairs.
Shared preferences allow you to store small amounts of primitive data as key/value pairs in a file on the device.
Yes, it is deprecated. Use the AndroidX Preference Library for consistent behavior across all devices. For more information on using the AndroidX Preference Library see Settings.
Dismiss Got it. Jetpack DataStore is a data storage solution that allows you to store key-value pairs or typed objects with protocol buffers. DataStore uses Kotlin coroutines and Flow to store data asynchronously, consistently, and transactionally.
quoting after Florina Mutanescu
SharedPreferences comes with several drawbacks: a synchronous API that can appear safe to call on the UI thread, no mechanism for signaling errors, lack of transactional API, and more. DataStore is a replacement for SharedPreferences that addresses most of these shortcomings. DataStore includes a fully asynchronous API using Kotlin coroutines and Flow, handles data migration, guarantees data consistency, and handles data corruption.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With