https://github.com/nameisjayant/jetpack-datastore-prefernce-example-2-android-kotlin
What is DataStore π€·ββοΈ? Jetpack DataStore is a data storage solution. It allows us to store key-value pairs (like SharedPreferences) or typed objects with protocol buffers DataStore uses Kotlin, Coroutines and Flow to store data asynchronously with consistency and transaction support π. In short, itβs the new data storage solution which is the replacement of SharedPreferences.
https://github.com/nameisjayant/jetpack-datastore-prefernce-example-2-android-kotlin
android datastore jetpack kotlin
Last synced: about 2 months ago
JSON representation
What is DataStore π€·ββοΈ? Jetpack DataStore is a data storage solution. It allows us to store key-value pairs (like SharedPreferences) or typed objects with protocol buffers DataStore uses Kotlin, Coroutines and Flow to store data asynchronously with consistency and transaction support π. In short, itβs the new data storage solution which is the replacement of SharedPreferences.
- Host: GitHub
- URL: https://github.com/nameisjayant/jetpack-datastore-prefernce-example-2-android-kotlin
- Owner: nameisjayant
- Created: 2020-09-14T03:48:48.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-14T03:51:01.000Z (almost 6 years ago)
- Last Synced: 2025-01-19T19:58:19.965Z (over 1 year ago)
- Topics: android, datastore, jetpack, kotlin
- Language: Kotlin
- Homepage:
- Size: 133 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jetpack-DataStore-Prefernce-Example-2-Android-kotlin
What is DataStore π€·ββοΈ? Jetpack DataStore is a data storage solution. It allows us to store key-value pairs (like SharedPreferences) or typed objects with protocol buffers DataStore uses Kotlin, Coroutines and Flow to store data asynchronously with consistency and transaction support π. In short, itβs the new data storage solution which is the replacement of SharedPreferences.
Why DataStore π€·ββοΈ First and my favourite reason π β Built withβ€οΈ Kotlin, Coroutines and Flow. If you have used SharedPreferences you might abuse or blamed it for something π then DataStore is here to rescue! SharedPreference has some drawbacks like it provided synchronous APIs -but itβs not MAIN-thread-safe! whereas DataStore is safe to use in UI thread because it uses Dispatchers.IO under the hoodπ. Itβs safe from runtime exceptions!ββ οΈ. What would be more satisfying that? π
It also provides a way to migrate from SharedPreferences π. It provides Type safety! (Using Protocol buffers). These are some reasons which encourage us to use DataStore and finally say goodbye to beloved SharedPreferences π.
Letβs begin code π¨βπ»
Weβll develop a sample Android application which stores a UI mode preference from user i.e. π Light Mode or π Dark Mode.