java - How to get the default value from XML ( not working ) -
when starting service need check particular setting ( boolean ). please check following code:
xml code:
<checkboxpreference android:title="enable sleep" android:defaultvalue="false" android:key="checkbox_preference"/>
java code:
sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(this); boolean sleepenabled = prefs.getboolean("checkbox_preference", true);
if(sleepenabled) {
// code
}
even tho, default value in xml "false" got "true" on every service start. know because i'm setting parameter in "getboolean()" method "true", need there actual value of checkbox ..
why getting "true" when starting service?
p.s if go settings , change value of checkbox it's fine. when starting service again pulls actual value. how actual default value set in xml?
change this:
boolean sleepenabled = prefs.getboolean("checkbox_preference", true);
to this:
boolean sleepenabled = prefs.getboolean("checkbox_preference", false);
and take @ documentation: http://developer.android.com/reference/android/preference/preference.html#attr_android:defaultvalue
Comments
Post a Comment