Prefer Storing Data with Jetpack DataStore
Posted by Florina Muntenescu , Android Developer Advocate, Rohit Sathyanarayana, Software Engineer Welcome Jetpack DataStore, now in alpha - 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 lets you store typed objects (backed by protocol buffers ) and Preferences DataStore , that stores key-value pairs . Data is stored asynchronously, consistently, and transactionally, overcoming most of the drawbacks of SharedPreferences. SharedPreferences vs DataStore * SharedPreferences has a synchronous API that can appear safe to call on the UI thread, but which actually does disk I/O operations. Furthermore, apply() blocks the UI thread on fsync() . Pending fsync() calls are triggered every time any service starts or stops, and every time an activity starts or stops anywhere in your application. The UI thread is blocked on pending fsync() calls schedul...