Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Jetpack DataStore is a new data storage solution and an alternative improvement upon Shared Preferences.
Jetpack DataStore library uses Kotlin coroutines and Flow for easier asynchronous reads and writes.
This library allows you to store key-value pairs or typed objects with protocol buffers.
Protocol buffers are Google’s extensible mechanism for serializing structured data.
There are different approaches in DataStore :
If you are interested to use Jetpack DataStore for storage in your application then this blog will help you to achieve your goal.
First, start with adding DataStore dependency in your Gradle file
if you want to use Proto DataStore, don’t forget to add the below dependency :
if you are using proto DataStore schema is defined in the proto file on app/src/main/proto/ directory.
Context.createDataStore() extension function is used to create an instance of Preferences DataStore with a mandatory name parameter which is the name of the Preferences DataStore.
Here two parameters fileName is the name of the file on app/src/main/proto/ which stores the data and serializer is the name of the serializer class which is CustomerSerializer in my case.
preferencesKey() is used with key for each value that needs to be store in DataStore.
edit() function is to updates the data in a DataStore.
For updating the stored data object use updateData() function.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.
Hussein Zawia
Co-founder, 24Dokan
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.