{"id":5537,"date":"2022-02-25T10:15:10","date_gmt":"2022-02-25T10:15:10","guid":{"rendered":"https:\/\/www.folio3.com\/mobile\/?p=5537"},"modified":"2022-03-02T11:12:26","modified_gmt":"2022-03-02T11:12:26","slug":"introduction-to-jetpack-datastore-alternative-to-sharedpreferences","status":"publish","type":"post","link":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/","title":{"rendered":"Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><strong>Introduction<\/strong><\/h1>\n\n\n\n<p>In mobile applications, some data has to be persisted to make the application startup faster, reduce network traffic or handle data completely offline. When we talk about data storage solutions for android, it is very common to think of SharedPreferences, it is a very simple\/fast way of persisting data in our app and it has been here for a while, but now Jetpack DataStore comes as a possible replacement for SharedPreferences and it\u2019s shortcomings.<\/p>\n\n\n\n<p>In this article, we will be exploring Jetpack DataStore to store data in our Android application.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>What is Jetpack DataStore?<\/strong><\/h1>\n\n\n\n<p>Google\u2019s definition:<\/p>\n\n\n\n<p><em>\u201cJetpack 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.\u201d<\/em><\/p>\n\n\n\n<p>DataStore provides 2 different implementations of Datastores:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><em>Preferences DataStore<\/em><\/li><li><em>Proto DataStore<\/em><\/li><\/ul>\n\n\n\n<p>In short, the first one is the same as how SharedPreferences work, it is simpler to implement but has no type-safety. The second one uses protocol buffers to serialize the data, it has a more complex implementation, but it comes with many advantages.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Preferences vs Proto DataStore<\/strong><\/h2>\n\n\n\n<p>The main objective of Proto DataStore is similar to Preferences DataStore, but the Proto DataStore is able to store objects with custom data types, it does not use key-value pairs like Preferences DataStore, just returns the generated object in a Flow. The generated object\u2019s type and structure depend on the schema of the .protoc file.<\/p>\n\n\n\n<p>A few key features of Proto DataStore over Preferences DataStore are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Provides type safety out of the box<\/li><li>Able to define list inside protoc schema with repeated marked fields<\/li><li>Requires learning of a new serialization mechanism, which depends on Protobuf but it is worth the effort.<\/li><li>Protobuf is faster than XML and JSON serialization formats<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Proto DataStore vs Room<\/strong><\/h2>\n\n\n\n<p>If Proto DataStore is able to store objects with custom data types then you might be thinking \u201cWhat to use Proto DataStore or Room?\u201d or \u201cWhy not use Room?\u201d. Well if you use Room to save only user\u2019s data, you need to create a database with a table, and also need to implement the query and insert functions. It sounds really inconvenient, so in this case, the Proto DataStore can be a hassle-free approach.<\/p>\n\n\n\n<p>In this article, we will be discussing and focusing on the <strong>Preferences DataStore<\/strong> and how to implement it.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Why Jetpack DataStore?<\/strong><\/h1>\n\n\n\n<p><em>\u201cIf you\u2019re currently using SharedPreferences to store data, consider migrating to DataStore instead.\u201d <\/em>&#8211; by <a href=\"https:\/\/developer.android.com\/topic\/libraries\/architecture\/datastore?gclid=CjwKCAjw8KmLBhB8EiwAQbqNoNcqipKfYNtRQlmWBcSWYo9e3dF-ti8LVLIce1y_9221Qt6tJ470xxoC6DgQAvD_BwE&amp;gclsrc=aw.ds#:~:text=If%20you%27re%20currently%20using%20SharedPreferences%20to%20store%20data%2C%20consider%20migrating%20to%20DataStore%20instead.\">Google<\/a><\/p>\n\n\n\n<p>DataStore aims to replace SharedPreferences as it is thread-safe and non-blocking. The concept behind DataStore is also quite similar to SharedPreferences, it uses key-value pairs to store data. Following are the benefits of using DataStore over SharedPreferences:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/zqrxrTkPx-JcNGyP2JrE52L362IUPiF7mfGlcDi2kBsfXlC1jenMD5pXHEPzqjb_aX1XGWzdarSeXy2yZcncifCCtJer3EQ5UQeZEg4elKmUevvZkMjWPoy9jDJLQrvsSsXFtF8I\" alt=\"\"\/><\/figure>\n\n\n\n<p><a href=\"https:\/\/developer.android.com\/codelabs\/android-preferences-datastore#3\"><\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Implementation (Preferences DataStore)<\/strong><\/h1>\n\n\n\n<p>It\u2019s time to get into the implementation part and see how to use Preferences DataStore in our application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 1: Dependencies<\/strong><\/h2>\n\n\n\n<p>To use Jetpack DataStore in our application we have to add the dependency in our app-level build.gradle file:<\/p>\n\n\n\n<p><em>implementation &#8220;androidx.datastore:datastore-preferences:1.0.0&#8221;<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 2: Create a DataStore<\/strong><\/h2>\n\n\n\n<p>To create a Preferences DataStore, we can use the <strong>preferenceDataStore<\/strong> delegate. The delegate will ensure that we have a single instance of DataStore with that name in our application.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/qrLlgDR1Nonfxch0F1HG0W6aG_l_b3493YmAWpyxRDao9NoMbbwBIEm2Dy6K1u1S7ljlQblIF9DdzWV8nccFG3Cb4z2TLOTZe7bxi0HFq-a5-EuerzB3A0B3T0VpcGw2PIf8Yfv5\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 3: Create keys to the DataStore<\/strong><\/h2>\n\n\n\n<p>Unlike SharedPreferences where you can use hard-coded string keys to write and read the data, DataStore requires key objects. We will need to create a key object and this is how we can create it:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/rYq5_t5Vdq8RdI8LTfwe0vm_t6L7qEFvjcOzH4YkgytqkwsY6Mk5RvdEs8uNu2i_MdwnSs5WtEWWLtkPoOLXPEqR9_z9N7svkqNfGHte80izApTfLP0xBm-9q8cPiPrmfmRySN8o\" alt=\"\"\/><\/figure>\n\n\n\n<p>This looks like an extra step but it is actually very helpful as your project becomes bigger, this will enforce developers to have all the keys in a centralized location.<\/p>\n\n\n\n<p>You can also create other types of PreferenceKeys:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><em>booleanPreferenceKey(name: String)<\/em><\/li><li><em>doublePreferenceKey(name: String)<\/em><\/li><li><em>floatPreferenceKey(name: String)<\/em><\/li><li><em>intPreferenceKey(name: String)<\/em><\/li><li><em>longPreferenceKey(name: String)<\/em><\/li><li><em>stringPreferenceKey(name: String)<\/em><\/li><li><em>stringSetPreferenceKey(name: String)<\/em><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 4: Write data to the DataStore<\/strong><\/h2>\n\n\n\n<p>Now that we have created our DataStore and PreferencesKey, it\u2019s time to write data to the DataStore, we need to call the edit() method, let\u2019s see how we can do that:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/T4qOnPYwPCnM3tYna-OcRZEnabCwzlAE1_ZO499R5U_ZOWkPCIadIcRYSTxjcUrzJiZkXWPocuEdxloqsr0Lf1ty7mr3kQHnNS_4MFT4D95HeYwIlTJE-lGH6HRoVJig9C8S5H6D\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 5: Reading data from DataStore<\/strong><\/h2>\n\n\n\n<p>To read the data from DataStore, we need to access the \u201c<em>data<\/em>\u201d property from the datastore, the data property is a <em>Flow&lt;Preferences&gt;<\/em>, so we can either get the entire preferences or map it into the value we actually want:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/sV1wocs-UR5WP8WDsXgFAXcmb4yZraRcmYrJxoNVbL1gLDI4CR7WrizGFtURoVWwEuYXW_gb1f4rOxdQ4_GXB9FDgOBgHoF0CaVKNdv61AAJK627pL1gWZZNsmcQ3ePVBQ01xU0Q\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 6: Handle Exceptions<\/strong><\/h2>\n\n\n\n<p>With the flow object we can also catch exceptions:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/hhUtBtaFUG8rwOddL5zBqLkuc5mXsqLtX6GhkfAkvXj2IrQ3oq-5zyNHAuTn5ekI3GYYMXGYTq50CVaTWyWQl3_p7hcvwlATqQnMygTCvGnvks8PBKoxjI3GRNyDbaTMYHoFfFTq\" alt=\"\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Migrating from SharedPreferences<\/strong><\/h1>\n\n\n\n<p>In order to be able to migrate from SharedPreferences to DataStore, we need to update the datastore builder to pass in a <strong>SharedPreferencesMigration<\/strong> to the list of migrations. DataStore will be able to migrate from SharedPreferences to DataStore automatically, for us. Migrations are run before any data access can occur in DataStore.&nbsp;<\/p>\n\n\n\n<p><em>Import <\/em><strong><em>SharedPreferencesMigration <\/em><\/strong><em>from <\/em><strong><em>androidx.datastore.preferences<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Qx6Efs5FbMd-S80YUlZ44bLT1P2mVAhIHwWuO6wwyY5PBLtS2DSy65UtjH12iUrSXX3N3oZLYYN9qdm_93UcHkTXqkonNGZo7bNHz1JabC2vVKty-2G7FmhIZUCUh-a8kduzRJXL\" alt=\"\"\/><\/figure>\n\n\n\n<p>That\u2019s it! It\u2019s that easy to migrate your data from SharedPreferences to DataStore. \ud83d\ude42<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h1>\n\n\n\n<p>Ideally DataStore is best to use with Kotlin and especially with coroutines. We don\u2019t need to worry about if our application uses standard SharedPreferences because migration is provided by the DataStore API.<\/p>\n\n\n\n<p>Because of the fact that DataStore handles data migration, guarantees data consistency, and handles data corruption, it is worth changing from SharedPreferences to DataStore.<\/p>\n\n\n\n<p>Feel free to share your responses and feedback below.<\/p>\n\n\n\n<p>Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In mobile applications, some data has to be persisted to make the application startup faster, reduce network traffic or handle data completely offline. When we talk about data storage solutions for android, it is very common to think of SharedPreferences, it is a very simple\/fast way of persisting data in our app and it &hellip; <a href=\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences&#8221;<\/span><\/a><\/p>\n","protected":false},"author":37,"featured_media":5538,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[48,47],"tags":[],"class_list":["post-5537","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-app-development","category-app-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Introduction to Jetpack DataStore - Alternative to SharedPreferences - Mobile App Development Services<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to Jetpack DataStore - Alternative to SharedPreferences - Mobile App Development Services\" \/>\n<meta property=\"og:description\" content=\"Introduction In mobile applications, some data has to be persisted to make the application startup faster, reduce network traffic or handle data completely offline. When we talk about data storage solutions for android, it is very common to think of SharedPreferences, it is a very simple\/fast way of persisting data in our app and it &hellip; Continue reading &quot;Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\" \/>\n<meta property=\"og:site_name\" content=\"Mobile App Development Services\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-25T10:15:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-02T11:12:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1703\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Noc Folio3\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Noc Folio3\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\"},\"author\":{\"name\":\"Noc Folio3\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/#\/schema\/person\/0b6e4f68efbd12d222ac9422766c61eb\"},\"headline\":\"Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences\",\"datePublished\":\"2022-02-25T10:15:10+00:00\",\"dateModified\":\"2022-03-02T11:12:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\"},\"wordCount\":891,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg\",\"articleSection\":[\"Android App Development\",\"App Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\",\"url\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\",\"name\":\"Introduction to Jetpack DataStore - Alternative to SharedPreferences - Mobile App Development Services\",\"isPartOf\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg\",\"datePublished\":\"2022-02-25T10:15:10+00:00\",\"dateModified\":\"2022-03-02T11:12:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage\",\"url\":\"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg\",\"contentUrl\":\"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg\",\"width\":2560,\"height\":1703},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.folio3.com\/mobile\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/#website\",\"url\":\"https:\/\/www.folio3.com\/mobile\/\",\"name\":\"Mobile App Development Services\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.folio3.com\/mobile\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/#organization\",\"name\":\"Mobile App Development Services\",\"url\":\"https:\/\/www.folio3.com\/mobile\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2020\/12\/folio3-mobile.png\",\"contentUrl\":\"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2020\/12\/folio3-mobile.png\",\"width\":210,\"height\":50,\"caption\":\"Mobile App Development Services\"},\"image\":{\"@id\":\"https:\/\/www.folio3.com\/mobile\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/#\/schema\/person\/0b6e4f68efbd12d222ac9422766c61eb\",\"name\":\"Noc Folio3\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.folio3.com\/mobile\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/29f05a21b8db20048e7717694b024bbd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/29f05a21b8db20048e7717694b024bbd?s=96&d=mm&r=g\",\"caption\":\"Noc Folio3\"},\"url\":\"https:\/\/www.folio3.com\/mobile\/blog\/author\/noc\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to Jetpack DataStore - Alternative to SharedPreferences - Mobile App Development Services","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to Jetpack DataStore - Alternative to SharedPreferences - Mobile App Development Services","og_description":"Introduction In mobile applications, some data has to be persisted to make the application startup faster, reduce network traffic or handle data completely offline. When we talk about data storage solutions for android, it is very common to think of SharedPreferences, it is a very simple\/fast way of persisting data in our app and it &hellip; Continue reading \"Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences\"","og_url":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/","og_site_name":"Mobile App Development Services","article_published_time":"2022-02-25T10:15:10+00:00","article_modified_time":"2022-03-02T11:12:26+00:00","og_image":[{"width":2560,"height":1703,"url":"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg","type":"image\/jpeg"}],"author":"Noc Folio3","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Noc Folio3","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#article","isPartOf":{"@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/"},"author":{"name":"Noc Folio3","@id":"https:\/\/www.folio3.com\/mobile\/#\/schema\/person\/0b6e4f68efbd12d222ac9422766c61eb"},"headline":"Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences","datePublished":"2022-02-25T10:15:10+00:00","dateModified":"2022-03-02T11:12:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/"},"wordCount":891,"commentCount":0,"publisher":{"@id":"https:\/\/www.folio3.com\/mobile\/#organization"},"image":{"@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage"},"thumbnailUrl":"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg","articleSection":["Android App Development","App Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/","url":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/","name":"Introduction to Jetpack DataStore - Alternative to SharedPreferences - Mobile App Development Services","isPartOf":{"@id":"https:\/\/www.folio3.com\/mobile\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage"},"image":{"@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage"},"thumbnailUrl":"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg","datePublished":"2022-02-25T10:15:10+00:00","dateModified":"2022-03-02T11:12:26+00:00","breadcrumb":{"@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#primaryimage","url":"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg","contentUrl":"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2022\/02\/chuttersnap-BNBA1h-NgdY-unsplash-min-scaled.jpg","width":2560,"height":1703},{"@type":"BreadcrumbList","@id":"https:\/\/www.folio3.com\/mobile\/blog\/introduction-to-jetpack-datastore-alternative-to-sharedpreferences\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.folio3.com\/mobile\/"},{"@type":"ListItem","position":2,"name":"Introduction to Jetpack DataStore &#8211; Alternative to SharedPreferences"}]},{"@type":"WebSite","@id":"https:\/\/www.folio3.com\/mobile\/#website","url":"https:\/\/www.folio3.com\/mobile\/","name":"Mobile App Development Services","description":"","publisher":{"@id":"https:\/\/www.folio3.com\/mobile\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.folio3.com\/mobile\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.folio3.com\/mobile\/#organization","name":"Mobile App Development Services","url":"https:\/\/www.folio3.com\/mobile\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.folio3.com\/mobile\/#\/schema\/logo\/image\/","url":"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2020\/12\/folio3-mobile.png","contentUrl":"https:\/\/www.folio3.com\/mobile\/wp-content\/uploads\/2020\/12\/folio3-mobile.png","width":210,"height":50,"caption":"Mobile App Development Services"},"image":{"@id":"https:\/\/www.folio3.com\/mobile\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.folio3.com\/mobile\/#\/schema\/person\/0b6e4f68efbd12d222ac9422766c61eb","name":"Noc Folio3","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.folio3.com\/mobile\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/29f05a21b8db20048e7717694b024bbd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/29f05a21b8db20048e7717694b024bbd?s=96&d=mm&r=g","caption":"Noc Folio3"},"url":"https:\/\/www.folio3.com\/mobile\/blog\/author\/noc\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/posts\/5537"}],"collection":[{"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/comments?post=5537"}],"version-history":[{"count":3,"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/posts\/5537\/revisions"}],"predecessor-version":[{"id":5566,"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/posts\/5537\/revisions\/5566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/media\/5538"}],"wp:attachment":[{"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/media?parent=5537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/categories?post=5537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.folio3.com\/mobile\/wp-json\/wp\/v2\/tags?post=5537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}