Monday, 19 August 2013

can't getPreferences but it keeps changes (can see in manu layout)

can't getPreferences but it keeps changes (can see in manu layout)

i've made the 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 made activity for 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);
}
} </code>
i can start that activity with preferences with menu/settings from main
activity and can see it works and store all changes when i close and start
my app agein:
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the
menu; this adds items to the action bar if it is 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;
} </code>
but when im trying to getPreferences it 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);
}
</code>
i see only default preferences, i mean every time my booleand are "true"
but in preferences layout there are "false"
i tried to see the android.develop but i'm new in java language and don
understand how to get any info from that site- to much everything and
unusefull

No comments:

Post a Comment