I have a similar problem like this , so I went according to the proposed solution and added this line of code to onCreate:
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
Unfortunately, the problem still occurs if the user has not changed the settings, but the default value (true) of
mPreferences.getBoolean(String.valueOf(day_of_week), true)
used instead of the default value from XML.
One suggested changing the default getBoolean () parameter to null, but this code causes the application to crash:
mPreferences.getBoolean(String.valueOf(day_of_week), (Boolean) null)
Any tips? Thanks in advance!
source share