Status Update
Comments
ow...@google.com <ow...@google.com>
lp...@google.com <lp...@google.com> #2
You can use PreferenceManager#setPreferenceDataStore
to set the data store for all preferences associated to the manager, which should work for this case. Would this work for your use case?
to...@yahoo.com <to...@yahoo.com> #3
well, let's face it. It's a design issue where the PreferenceDataStore
was bolted on as an after-though / special case.
I honestly don't see how it can be fixed when inflating from xml (but would love to be wrong).
I temporarily went ahead with PreferenceManager#setPreferenceDataStore
as I saw no alternative.
Perhaps my best way forward is to drop the Preference library altogether; it had to implement too many workarounds by now.
But may I suggest you update the documentation about using `Preference#setPreferenceDataStore' so other people don't have to debug that library.
Description
re-opening https://issuetracker.google.com/141678219
hitting this same issue.
My code:
Here is a debug trace:
The library code:
It's easy to see that the call to setPreferencesFromResource() ends up using the value from SharedPreferences and not from my datastore. But I can't set a PreferenceDataStore until that call is done.
Conclusion: when using setPreferencesFromResource, you simply cannot use PreferenceDataStore. I presume no one tested this?
I don't fancy building my preference screen totally from code just to be able to set the PreferenceDataStore. In that case I might as well just dump the whole preference library.
any thoughts?
and please do not say "migrate to the new datastore/kotlin/flow" - I'd have to dump the preference library as well to do that + add the mess called 'kotlin' ; no thanks.