Member-only story

Is Jetpack DataStore a replacement for SharedPreferences?

A Jetpack recommended solution for storing data asynchronously

Satya Pavan Kantamani
ProAndroidDev
5 min readJul 11, 2021

--

Introduction

SharedPreferences is the common way used for storing key-value pairs in local storage. We have been using the SharedPreferences concept since the start of Android development. As we are migrating to the latest programming languages like Kotlin there needs to be an advancement in terms of dealing with SharedPreferences. SharedPreferences have their downsides which will see in upcoming parts of this post. Also frequently changing properties may cause issues.

In this post let’s see what are the disadvantages of SharedPrefrences, What is DataStore, Why do we need it, and basic implementation stuff. Familiarity with coroutines and Kotlin Flow is needed for understanding this.

If you want to jump directly to the code base, check out the GitHub repo.

Disadvantages of SharedPreferences

Before going to check out DataStore we need to know the problems of existing SharedPreferences. There are few disadvantages that may cost us if not used in a proper way

  • They are not safe to call on UI thread although as they have asynchronous API that can appear to be safe to…

--

--

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Satya Pavan Kantamani

Android Dev, Interested in Traveling, App development. Based in Hyderabad, India. Catch me at https://about.me/satyapavankumar

Responses (2)

Write a response