Using PreferenceActivity, Android automatically saves simple preferences such as checkboxes being checked etc. I have a couple of questions:
1 - where do these preferences get saved? Is it the same preferences file that PreferenceManager.getDefaultSharedPreferences(Context) returns?
2 - is there a way to use a difference set of preferences? I.e. with context.getSharedPreferences (String name, int mode) you supply a string to identify a particular set of preferences. Is it possible to save preferences from a PreferenceActivity in a set of preferences returned like this?
Thanks in advance, Barry
Yes it's possible.
Have a look at that : https://idlesun.blogspot.com/2012/12/how-to-make-preferenceactivity-use-non.html
public class MyPreferencesActivity extends PreferenceActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager prefMgr = getPreferenceManager();
prefMgr.setSharedPreferencesName("my_preferences");
prefMgr.setSharedPreferencesMode(MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.preferences);
}
}
addPreferencesFromResource()
have to be called after setSharedPreferencesName()
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With