2

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 DefaultSharedPreferences.

I need this, cause I have a Widget with a button that needs to set this value to true/false

Zon
  • 18,610
  • 7
  • 91
  • 99
Alex
  • 2,213
  • 4
  • 32
  • 44

2 Answers2

2

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

maid450
  • 7,478
  • 3
  • 37
  • 32
0

Use the shared preferences editor: http://developer.android.com/reference/android/content/SharedPreferences.Editor.html

George
  • 3,727
  • 9
  • 31
  • 47