Question

two activities here, A and B. A is main, B is PreferenceActivity with two EditTextPreference.

I want to be able to access the preferences generated by B from activity A, and for that I need of course (I guess) getSharedPreferences on A. But in order to do that I need to supply the preference file for the activity that generated it. This is tedious (long names), erratic at best (depends on the activity that generated it), and finally it's a mess, because it's much better to keep everything under one xml file, with a name that is well known to all my activities. And besides, if I have 100 activities, how would I keep track of preference files anyway...

So the point is: how do I "bind" an EditTextPreference in a way that the changes are made to a given preference file, not the one automatically generated by Android?

Was it helpful?

Solution

I'm not quite sure why you want to use a specific preferences file. Why not the default one?

SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(this); gives you the shared preferences that are valid all across your application. What was written in your PreferenceActivity will be in there.

OTHER TIPS

Use a static string in one of your classes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top