In my application, I am attempting to use sharedPreferences to save some basic settings as well as a Preference Screen. The name for my sharedPreferences is appPrefs and thus my file name is .../appPrefs.xml However, my app screen saves it's preferences in the defaultSharedPreference file which is com.COMPANY.PACKAGENAME_preferences.xml
What I would like to do is have my preference screen read/write its preferences to the appPrefs file. I have looked in the API and can't find anything. Am I stuck managing two sharedPreference files?
Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment. getDataDirectory() .
Open your phone's Settings app. Default apps. Tap the default that you want to change. Tap the app that you want to use by default.
Just to answer the question about how to use different shared settings name with the new PreferenceFragment API, you need to add the following code when overriding onCreate:
public static class PrefsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager manager = getPreferenceManager(); manager.setSharedPreferencesName("YOUR_SETTINGS_NAME"); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); } }
Did you try:
PreferenceManager.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