Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
In short
On the pagehttps://developer.android.com/topic/libraries/architecture/datastore it is not clear where to create the
DataStore
and there's further confusion about files.Snippets
(BTW, "in the kotlin file" is mentioned in 2 places on this page)
There's also a reference to a file elsewhere on the page:
Detailed description
What files are we talking about?
DataStore file
I assume the
DataStore
is backed up by a file, and that's the "given file"? But this concept of a DataStore representing an underlying file isn't explained in the introduction."The kotlin file"
I have many kotlin files. Apparently we're talking about a singleton instance. Does it matter which kotlin file to create this in? In some other documentation (a code lab on DataStore) it says
This seems to suggest that it's ok if you have one activity, but not recommended. So, what do I do in a bigger project?
In the worst case, this all could be wrongly interpreted as that you "may only create a DataStore once in every kotline file" I'm pretty sure that is not what is meant.
Suggestion
Make it clear what files we're talking about and where it's ok to create the DataStore. Clearly explain different possibilities to instanciate a DataStore. For example, I noticed that the now-in-android app seems to inject the
DataStore
via Hilt, so that seems to be a possibility.