java - can't getPreferences but it keeps changes (can see in manu layout) -
i've made special preferences layout.
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <checkboxpreference android:key="pref_sound" android:title="@string/pref_sound" android:summary="@string/pref_sound_summ" android:defaultvalue="true" /> <checkboxpreference android:key="pref_vibro" android:title="@string/pref_vibro" android:summary="@string/pref_vibro_summ" android:defaultvalue="true" /> <checkboxpreference android:key="pref_screen" android:title="@string/pref_screen" android:summary="@string/pref_screen_summ" android:defaultvalue="true" /> </menu>
and activity it.
package com.actionandresttimer; import android.os.bundle; import android.preference.preferenceactivity; public class prefs extends preferenceactivity { @suppresswarnings("deprecation") @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); addpreferencesfromresource(r.xml.cboxpreferenses); } }
i can start preferences activity via menu/settings main activity , works. stores changes when close , start app again:
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. //getmenuinflater().inflate(r.menu.main, menu); //return true; super.oncreateoptionsmenu(menu); menuinflater inflater = getmenuinflater(); //inflater.inflate(r.menu.menu, menu); inflater.inflate(r.menu.main, menu); return true; }
but when i'm trying call getpreferences
, doesn't work
public void getprefs() { // spref = getpreferences(mode_private); // spref = preferencemanager.getdefaultsharedpreferences(prefs); spref = this.getsharedpreferences("com.prefs", context.mode_private); cboxsoundstatus = spref.getboolean("pref_sound", true); cboxvibrostatus = spref.getboolean("pref_vibro", true); cboxscreenstatus = spref.getboolean("cpref_screen", true); }
i can see default preferences settings. boolean set true
in preferences activity layout displayed false
i tried android developer website, i'm new java programming , don't understand how information official documentation website.
try code
sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(getapplicationcontext());
prefs.getboolean("pref_sound", true);
Comments
Post a Comment