Using XML preferences, how can I make some of the `Preference`s use a different `SharedPreferences` instance?

45 Views Asked by At

I am using XML preferences and PreferenceFragmentCompat. I want to encrypt some of the values, such as passwords, but not others, such as theme settings. It seems that what I want to use would be EncryptedSharedPreferences. But I'm not sure how to make it work with the UI. I see two issues:

  • There seems to be no way to specify that this or this Preference should be using this or this SharedPreference instance;
  • There seems to be no way of making PreferenceFragmentCompat use anything other than a single standard SharedPreference file, as set by methods such as PreferenceManager#setSharedPreferencesName.

The questions are,

  • What's a way to make this work with minimal changes to the current codebase? And,
  • What would be the ideal way to make this work if I'm willing to do a considerable rewrite?
0

There are 0 best solutions below