DEV Community

Discussion on: Beyond preferences

Collapse
 
tkuenneth profile image
Thomas Künneth

Hello. Happy to answer some of your questions.

Is DataStore ready to replace SharedPreferences
completely? Including usage in SettingsActivity/PreferenceFragmentCompat?

It covers quite a lot of aspects. I don't know, though, if the coverage is complete. Regarding UI, there is a nice article by Jordan Hansen covering this.

Is there any way to see the content of the new files
(seems they are in "files/datastore/....preferences_pb" path) ?
Via the IDE? Somewhere else?

Yes, through the Device File Explorer. Open it with View - Tool Windows - Device File Explorer.

Device File Explorer

What is the format of these files, anyway?

File opened in Androi Studio

A binary file format. Unfortunately I do not know if there is a viewer for it.

Is there an equivalent of getDefaultSharedPreferences ? Or I always have to tell which file to use ?

Well, as the docs say:

Creates a property delegate for a single process DataStore. This should only be called once in a file (at the top level), and all usages of the DataStore should use a reference the same Instance.

So you should use the same file.

I know you shouldn't create large SharedPreferences files, as it could be inefficient and even cause OOM. Is it true for DataStore too?

A main feature of DataStore is being asynchronous. It was built to overcome inefficiencies of the old preferences api. I did not do any profiling, though.

Sincerely hope this helps.

Collapse
 
androiddeveloperlb profile image
AndroidDeveloperLB
  1. OK seems it's supported there. Just not sure how to do it. Know of any nice sample of using it there?
  2. Yes I meant how to read them and view them...
  3. So I should choose some file that will be used for all (if I use a single file), right?
  4. Thanks.
  5. What about the theme&splashScreen question?
Thread Thread
 
tkuenneth profile image
Thomas Künneth

OK seems it's supported there. Just not sure how to do it. Know of any nice sample of using it there?

No, I'm sorry, nothing besides what's shown in the link (article)

Yes I meant how to read them and view them...

I'm aware of now viewer app, sorry. But as you can see from my code, access is really simple, so if I were to inspect the file, I would probably just iterate over the keys and print the values to console

So I should choose some file that will be used for all (if I use a single file), right?

Yes.

What about the theme&splashScreen question?

I might do a short demo in the future, but as of tight schedule can't say when.

Thread Thread
 
androiddeveloperlb profile image
AndroidDeveloperLB

Too bad.
Please let me know if you add a demo.