iflorit
iflorit

Reputation: 749

Access Custom Preferences set on a PreferenceActivity

How can I access to the shared preferences set on a PreferenceActivity? It generates de proper XML on my shared_prefs folder, but when I access like

prefs=MatchappApplication.INSTANCE.getSharedPreferences("app_settings",
    Activity.MODE_WORLD_READABLE);
prefs.getBoolean("show_weather_notifications",true);

it doesn't work (returns true always, even if I change the value in the PreferenceActivity).

How I must to access this preference?

Thnks!

Upvotes: 1

Views: 50

Answers (1)

iflorit
iflorit

Reputation: 749

Ok, I found the error.

In my CustomPreferenceActivity, I must to setSharedPreferencesMode

PreferenceManager manager = getPreferenceManager();
manager.setSharedPreferencesName("app_settings");
manager.setSharedPreferencesMode(MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.app_settings);

It works now!

Upvotes: 1

Related Questions