Questions tagged [android-jetpack-datastore]
134 questions
29
votes
5 answers
How to clear jetpack datastore data on specific condition
i've been using jetpack datastore for a while, but then i got a problem.
I want to clear data in datastore when the app is destroyed.
Im using jetpack datastore to persist data only in form
i've searched that sharedPreferences has a clear()…

Pif
- 530
- 2
- 10
- 20
25
votes
4 answers
Provide preferences datastore with Hilt
I was trying to provide a common DataStore so that the same preference file could be used in multiple places but I got the helpful error message:
Cannot find symbol:…

Barry Irvine
- 13,858
- 3
- 25
- 36
24
votes
1 answer
android datastore-preferences: Property delegate must have a 'getValue(Context, KProperty<*>)' method
I'm writing a jetpack compose android app, I need to store some settings permanently.
I decided to use androidx.datastore:datastore-preferences:1.0.0 library, I have added this to my classpath.
According to the…

Dániel Kis
- 2,341
- 5
- 28
- 51
20
votes
3 answers
Jetpack proto datastore - gradle config with Kotlin dsl
In jetpack datastore, you have to set the gradle plugin task for generating class out of .proto files:
// build.gradle
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
// Generates the java Protobuf-lite code…

Mahdi-Malv
- 16,677
- 10
- 70
- 117
17
votes
3 answers
Androidx Preferences Library vs DataStore preferences
I had previously replaced SharedPreferences in my app with the new DataStore, as recommended by Google in the docs, to reap some of the obvious benefits. Then it came time to add a settings screen, and I found the Preferences Library. The confusion…

fafcrumb
- 333
- 3
- 13
16
votes
5 answers
How to use Android DataStore with multi users or files
I want to store some preferences using DataStore. But the problem is that my application can have multiple users and therefor needs to store these preferences in separate files. I got a working example using only one user but I'm struggling to…

Wirling
- 4,810
- 3
- 48
- 78
15
votes
2 answers
Proper instance creation of Android's Jetpack DataStore (alpha07 version)
So with the new alpha07 version, Android ditched the private val dataStore = context.createDataStore(name = "settings_pref"), however the new way they use datastore doesn't work for me.
Since upgrading from…

Borna Ungar
- 305
- 2
- 8
14
votes
4 answers
How to open jetpack DataStore file (.preferences_pb)
I am trying out new jetpack DataStore library . I saved data using the library . This created a file settings.preferences_pb in app data directory (/data/data/my.package.name/files/datastore/settings.preferences_pb) . setting is the file name given…

Manohar
- 22,116
- 9
- 108
- 144
10
votes
0 answers
DataStore not receiving event from Flow
I am playing with datastore-preferences:1.0.0-alpha01 and I cannot seem to get an event back when the datastore value has been updated. I have been trying to observe it in the fragment and the parent activity with the same result. When I create an…

DevinM
- 1,112
- 1
- 12
- 29
9
votes
1 answer
How to perform version migrations in Android Jetpack Datastore
Performing a migration from SharedPrefs into DataStore is straightforward and documented very well.
However when I want to do a simple "version bump" migration from DataStore to still DataStore, meaning some keys might have changed etc. how should…

Stylianos Gakis
- 862
- 8
- 19
8
votes
2 answers
How to implement Datastore in java based android app?
I can only find ways to implement datastore through Kotlin. I have tried creating it with
DataStore datastore = new Datastore but as soon as proceed with it, it overrides to methods namely save and loadData but the…

Prabhav Sharma
- 108
- 1
- 7
7
votes
1 answer
Observing Android Jetpack DataStore Value Change
Am I missing something or is it not possible to attach a listener to the new Android Jetpack Preference Datastore? I thought the whole point of using Flow is that we can call flow.toLiveData() on the Preference Datastore and observe changes to the…

Val Okafor
- 3,371
- 13
- 47
- 72
6
votes
2 answers
Proto datastore jetpack compose - gradle dependencies exception
I followed this codelab from the android developer platform: https://developer.android.com/codelabs/android-proto-datastore#4
Added the same exact dependencies as shown in the codelab and I get the following gradle exception when trying to sync
A…

Giuliopime
- 707
- 4
- 21
6
votes
1 answer
How to use DataStore with StateFlow and Jetpack Compose?
I try to give the user the choice whether to use the UI Mode 'light', 'dark' or the 'system' settings. I would like to save the selection as DataStore.
The drop down menu for the user selection is not loading the value from DataStore. It is always…

Ohlsen
- 185
- 1
- 8
6
votes
1 answer
Why is Datastore slower than Shared Preferences
I was checking the execution time of datastore and shared preference and I observed that datastore takes more time than shared preference.
This is my code
suspend fun saveUser(user: User, context: Context) {
val userString =
…

Rahul J
- 63
- 3