I am attempting to use a custom implementation of the SharedPreferences interface to persist an application’s preferences to a database (instead of the default XML).
Why? I’d like to use the convenience of PreferenceActivity to construct the UI but this app will be used on multiple devices so the preferences a user sets need to persist across devices.
So.. I’ve got the implementation written, but can’t figure out how to associate a particular SharedPreference with a PreferenceActivity. I know that uses getSharedPreferences(), but how can I override that? Can i register my SharedPreferences somehow? I did not see anything in the API to do this.
Or … if I’m going about this all wrong please let me know. Thanks.
I’ve been investigating this question some time ago. For a different reason though.
What I found is that
PreferenceActivityis highly coupled withPreferenceManagerand it usesPreferenceManager.getDefaultSharedPreferences()deep inside to getSharedPreferenceinstance. And there is no way to either substitute customPreferenceManagerorSharedPreferenceinstance insidePrefernceActivity.I found that Preference framework is inflexible and it’s quite hard to extend or change default behaviors, and sometimes its even impossible. But my guess is that designers of this this framework had “ease of use” as their top priority, not extendability and flexibility. Which is understandable.