r/android_devs • u/shreyaspatil99 • Sep 12 '20
Article Proto DataStore - Hello DataStore, Bye SharedPreferences
https://medium.com/scalereal/hello-datastore-bye-sharedpreferences-android-part-2-proto-datastore-2716fbfd47833
u/Zhuinden EpicPandaForce @ SO Sep 12 '20
I don't feel the need to write a proto schema, I think this is aimed at people who were storing JSON strings in SharedPreferences.
3
u/shreyaspatil99 Sep 13 '20
Yeah! SQLite (Room DB) is good solution for storing "actual schema based data".
4
u/Pzychotix Sep 13 '20
If anything, it probably arose out of internal needs, considering they developed it. I know a bunch of AOSP stuff makes use of it, and I'd bet their first party apps use protobufs as well.
10
u/phileo99 Sep 12 '20 edited Sep 12 '20
Is Proto Datastore just another shiny new trinket that Google is selling?
If I am using SharedPreferences in my existing project, and I have only simple primitives to store/retrieve, and I don't notice any customer complaints with my app, then what possible incentive do I have to spend effort and money to migrate all of that already working code to Jetpack Datastore?
"Oh, but JetPack DataStore offers type safety"
But you can get similar type safety by declaring private sharedPref keys in a companion object and enforce access to those SharedPref keys through public methods in the same companion object to put/get the SharedPrefs. Boom, Single Responsibility Principle and type safety without yet another Gradle Dependency.
Change my mind.
5
Sep 12 '20
No one has to change your mind. If you don't find the library useful for your needs, don't use it.
9
u/phileo99 Sep 12 '20 edited Sep 12 '20
It's just that I find it annoying to see these random Medium articles that blindly cheer on the latest shiny trinkets being sold by Google without any critical thought process behind it.
I disagree with how Google is trying to convince us that SharedPreferences is so evil that it must be deprecated
I disagree with the reasoning that Android Developers should use JetPack Datastore just because it solved a File I/O problem that was never a problem for app customers. I may give JetPack Datastore a try, but it won't be because of some obscure File I/O problem
In all my years as an Android Developer, I have not come across any app users who complained about problems where File I/O is the root cause
4
u/gabrielfv Sep 13 '20
Precisely. Let's be honest for a moment, why would I want to tinker with protocol buffer schemas, extra gradle configuration and an extra class to do what SharedPreferences already do very reliably if you're careful enough? The problem is not that Proto DataStore is bad, it's not, there's certainly good usecases for it where all of that makes sense, but sharedpreferences already fill for a simple yet useful resource for most of the scenarios I find myself using it. If you were storing complex data and don't want to bother with relational databases, there you have it, but it does not replace sharedpreferences unless you were abusing it.
1
u/CraZy_LegenD Sep 14 '20
I think that this protostore is coming to Android cause of compose since it eliminates problems with it being called on the UI thread.
Another problem with Shared prefs is that it's synchronus but sometimes you need the exact opposite and without encrypted shared prefs, shared prefs is just weak, here you get some benefit, thus it's faster than shared prefs (i think so, not sure about this).
2
u/Thomas_Vos Sep 14 '20
How can we use DataStore for values that need to be known immediately in an Activity onCreate?
For example, the user can configure an app theme in the settings. (saved to SharedPreferences at the moment). When the app is started, the app reads the saved value, and calls `setTheme` before calling `super.onCreate` in an Activity. How would that be possible with DataStore if the values cannot be read on the ui thread?