Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change Preferences file name?

Tags:

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?

like image 221
user543010 Avatar asked Jun 13 '11 01:06

user543010


People also ask

Where is the preferences file android?

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() .

How do I set default preferences?

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.


2 Answers

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);     } } 
like image 143
dragoon Avatar answered Sep 29 '22 13:09

dragoon


Did you try:

PreferenceManager.setSharedPreferencesName  
like image 34
Snicolas Avatar answered Sep 29 '22 13:09

Snicolas