• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Preference is saved in wrong place

QuickNick

Newbie
Good day, friends.

I'm wanting to build preference activity.
In the main activity I've wrote:
Code:
localPreferences = getSharedPreferences("My preferences", 0);
loopSound = localPreferences.getBoolean(getString(R.string.keyLoopSound), false);
I wrote in string.xml:
Code:
    <string name="preferenceTitle">My Tuner options</string>
    <string name="keyLoopSound">keyLoopSound</string>
    <string name="valueLoopSound">Loop sound</string>
In my_tuner.xml I've wrote:
Code:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/preferenceTitle">
    <CheckBoxPreference android:key="@string/keyLoopSound" android:title="@string/valueLoopSound" />
</PreferenceScreen>
And in preference activity I've made:
Code:
addPreferencesFromResource(R.xml.my_tuner);

I've checked and unchecked checkbox, but its value is independent to the value in the main activity.

"loopSound" in main activity remains false despite of checked checkbox.
As I understand, my preference activity stores value in the another workspace, not in the "My preferences".

What's solution?
 
Back
Top Bottom