How to set a DefaultSharedPreferences value?
I have a preferences activity with a checkbox "Enable Service".
I read the value like this :
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(con);
ServiceEnabled_Pref = prefs.getBoolean("EnableService", true);
ok, but how can I set this Preference ?
this is not a CustomShared Preference, It is a DefaultShared Preferences and it seems that there is not a method putBoolean for开发者_Python百科 DefaultSharedPreferences.
I need this, cause I have a Widget with a button that needs to set this value to true/false
programatically:
prefs.editor().putBoolean("EnableService", true).commit();
however your best bet for defining the preferenceActivity and its defaults is via an xml file as decribed here with the android:defaultValue
attribute
Use the shared preferences editor: http://developer.android.com/reference/android/content/SharedPreferences.Editor.html
精彩评论