How To Use Android’s Preferences DataStore | Android Jetpack Tutorial

preview_player
Показать описание
Medium article "Hot to use Androids Preferences DataStore with Helper functions"

Link to the SharedPreferences comparison table:

Support me on Medium:

Follow me on:
Рекомендации по теме
Комментарии
Автор

"I can finally see what we're doing here" 😂 👌 good one

codinginflow
Автор

The old Shared Preferences is king 👑.

Now the datastore & proto store too much boiler code.

Sj-yfjg
Автор

How did you migrate the old sharedPreferences to datastore, how did you map the existing values

AugustinBunani
Автор

I have a few notes:
1. 4:38 I don't think it's wise to have a field of the editor of the SharedPreferences. I think you should create a new one for each transaction.
2. Does DataStore finally support Preferences (of settings screens) ? If not, it still can't replace SharedPreferences.
3. There is no way to use this on Java? I've noticed you used "suspend"...
4. Is there a way to avoid "suspend" and just use an annotation of "WorkerThread" instead? Or use a liveData? Or something else?
5. How would you load which theme to use (when there is a setting for it for users), if themes needs to be set right away on the onCreate (otherwise there would be a split second that the wrong background could be shown)? Any nice way to do it via the splash-screen API, perhaps?
6. 11:49 Why didn't they make such things shorter? It seems about twice as longer compared to SharedPreferences...
7. It seems you've set "false" as default value twice: once in the viewModel, and another time in the class you've created to hold the values. How come?

LiranBarsisa