I have implemented some app preferences for my app. For strings they work great but not for boolean values. E.g.
public class MdSharedPrefs {
public final static String PREFS_NAME = "prefs";
public static boolean getSSFlag(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
return prefs.getBoolean(context.getString(R.string.pref_key_ss), false);
}
public static void setSSFlag(Context context, boolean newValue) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
Editor prefsEditor = prefs.edit();
prefsEditor.putBoolean(context.getString(R.string.pref_key_ss),
newValue);
prefsEditor.commit();
}
}
And this requires
<string name="pref_key_ss"></string>
in strings.xml. When I remove this line the project wont compile. But when I leave it this boolean pref does not work. When I click it and go back to main screen and then go back to prefs the value is not checked.
However for strings it works fine.
Any ideas whats wrong?
in my application i am using like this it’s working fine
declaration
getting
storing like this