Can I use my current SharedPreferences tag to store the values from a PreferenceActivity?
Currently, I'm using the following code across all of my activities in my app to store application level variables and carry values between activities..
prefs = this.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
I didn't have a PreferenceActivity prior to this, but now I do and I am looking to store a few user prefs from this new Pre开发者_如何学GoferenceActivity in the same sharedPreferences tag, "MyPrefs".
I know I can access the PreferenceActivity SharedPrefs from my activities via
prefs = PreferenceManager.getDefaultSharedPreferences(this);
but I would like those values saved to my current sharedPreferences tag, "MyPrefs", but I'm not sure how to do this.
Thanks in advance..
You can change the default name of SharedPreferences file used by PreferenceActivity. I did this in onCreate method of PreferenceActivity by adding the following piece of code:
getPreferenceManager().setSharedPreferencesName("MyPrefs");
Yes, you can http://idlesun.wordpress.com/2011/04/08/how-to-make-preferenceactivity-use-non-default-sharedpreferences/
You can't. the PreferneceManager always uses this.getPackageName () + "_preferences as preference name. Sorry to break the bad news. This is also important when you wish to use the new backup framework.
You can of course replace MyPrefs with this.getPackageName () + "_preferences.
精彩评论