I have implemented an application Preferences Fragment using a Class that extends class PreferenceFragmentCompat.
public class SettingsFragment extends PreferenceFragmentCompat
The fragment is reading a preferences XML file called Preferences.xml
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
}
and using Default SharedPreferences to store the preferences.
I now want to add a second Preferences Fragment that is independent of the first one.
Let’s assume I will use a different XML file.
I already created a second SharedPreferences file (item_prefs.XML) that is not the default one, and written data into it:
Context context = getContext();
SharedPreferences preferences = context.getSharedPreferences("item_prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
String krd = context.getString(R.string.key_ring_duration);
editor.putString(krd, "15Seconds");
editor.commit();
I can’t find a way to associate my second file (item_prefs.XML) with my second Preferences fragment.
It always using the default SharedPreferences file.