this is not quite what you are asking for, but here is what i am doing:
in my main action, when I call a preference activity, I pass it the name of the user preference file as additional data in the intent:
static final String EXTRA_PREFERENCES_NAME = "android.intent.extra.PREFERENCES_NAME"; ... Intent intent = new Intent(this, Preferences.class); intent.putExtra(EXTRA_PREFERENCES_NAME, preferencesName); startActivity(intent);
then in my preferences setting, I get the name of the user settings and set it like this:
public class Preferences extends PreferenceActivity { private String preferencesName = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
Finally, in my main action, I get specific settings like this:
SharedPreferences preferences = getSharedPreferences(preferencesName, MODE_PRIVATE); String somePreference = preferences.getString("somePreference", defaultValue);
source share