-
Notifications
You must be signed in to change notification settings - Fork 2
Data Store
Devrath edited this page May 1, 2021
·
2 revisions
- Datastore is a component of data storage solution from the android jetpack.
- It allows us to store the
key/value
pairs like shared preferences or typed objects with protocol buffers. - Data store uses kotlin, coroutines, and flow to store data asynchronously with consistency and transaction support
-
Shared Preferences
aresynchronous
and not main thread-safe, But data store is safe to use in the main thread since it usesDispatchers.IO
under the hood. -
Shared Preferences
are not safe from runtime exceptions, But theData-Store
is safe from runtime exceptions - There is an easy way to migrate from
Shared Preferences
Preference Data Store | Proto Data Store |
---|---|
- Here we have a fragment where we are storing a value entered in edit-text, on click of save button, We have used global scope here
- We are displaying the data from the
dataManager
helper class that gets the data from the data store via a flow and displays the data in the text view - View <->ManagerClass