Reputation: 2594
I'm building an Android application and I have preferences stored in classes loaded from the web (we sync preferences with a website) however using a PreferenceScreen, they seem to get ignored when using the correct APIs.
In XML I have turned off persistence and I make sure in Java like so p.setPersistent(false);
then I set the default value p.setDefaultValue( boolean );
I use only EditTextPreferences and CheckBoxPreferences, and both these don't work. I've tried setting it in the Editor, but it doesn't seem to work.
Thanks,
Joe
Upvotes: 4
Views: 539
Reputation: 2594
Finally managed to do it. Thanks to the extremely clever people at Google, they made this incredibly difficult as preferences seem to only be set at design time (bit silly).
I made an interface called FlushPreferences
which implemented a method similar to setDefault, and made subclasses of the preference classes I was using EditTextPreference
and CheckBoxPreference
which they called the onSetDefaultValue
internal function getting them to show up properly.
Code: https://gist.github.com/1430073
(P.S Anybody who sees this at Google: Please fix it for Android 4.1 or something)
Upvotes: 5