Reputation: 3953
I am having three files in xml folder
beginning_text.xml
preferences.xml
caller.xml
All three files are used as SharedPreferences file
Can i use all three files as
PreferenceManager.setDefaultValues(this, R.xml.sms_beginning_text, false);
addPreferencesFromResource(R.xml.sms_beginning_text);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
addPreferencesFromResource(R.xml.preferences);
PreferenceManager.setDefaultValues(this, R.xml.caller, false);
addPreferencesFromResource(R.xml.caller);
and then reading it like:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
or how can i read and save 3 different files?
Upvotes: 1
Views: 83
Reputation: 16354
Declare the names of your preference files and while retriving the preferences, mention the name of that file which you want to access in getSharedPreferences().
Here I declare two file names : PrefFile and PrefFileNEW; then I pass the respective names to the getSharedPreference() while retrieving the preferences.
public static final String PREF_FILE_NAME = "PrefFile";
public static final String PREF_FILE_NAME_NEW = "PrefFileNEW";
SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
{
//access your preferences here
}
SharedPreferences preferences_new = getSharedPreferences(PREF_FILE_NAME_NEW, MODE_PRIVATE);
{
//access your preferences_new here
}
Hope it helps.
Upvotes: 1