Android preferences seem to ignore setDefaultValue

I am creating an Android application and I have settings stored in classes downloaded from the Internet (we synchronize settings with the website), however, using PreferenceScreen, they seem to be ignored when using the correct APIs.

In XML, I turned off persistence, and I'm sure in Java, for example, p.setPersistent(false);

then I set the default p.setDefaultValue( boolean );

I use only EditTextPreferences and CheckBoxPreferences, and both of them do not work. I tried to install it in the editor, but it does not work.

Thanks,

Joe

+4
source share
1 answer

Finally managed to do it. Thanks to the extremely smart people at Google, they made it incredibly complicated, as preferences seem to be set only during development (a little silly).

I created an interface called FlushPreferences , which implemented a method like setDefault, and subclassed the preference classes that I used EditTextPreference and CheckBoxPreference , which they called the onSetDefaultValue internal function, so that they would display properly.

Code: https://gist.github.com/1430073

(PS Anyone who sees this on Google: fix it for Android 4.1 or something like that)

+5
source

Source: https://habr.com/ru/post/1383444/


All Articles