android - PreferenceActivity with two SharedPreferences -


how create preference screen can save values in 2 different shared preferences ?

for example, in preferenceactivity first preference checkboxpreference. state of checkbox saved in "user_86_prefs" sharedpreferences , second preference listpreference, , state of selected item saved in "deviceprefs" sharedpreference.

in preferencefragment can

getpreferencemanager().setsharedpreferencesname("user_86_prefs"); 

actually sharedpreference named "user_86_prefs" specific user connected on app, , "deviceprefs" specific device.

should create class extends preferencefragment, , put preferences specific device inside ? if yes, how can have 2 preferencesfragments in same activity ?

thanks

one way of doing create 1 class in wich handle preferences.

public class mysharedpreferences{      private static final string user_pref = "user_shared_pref";     private static final string device_pref = "device_shared_pref";      private static sharedpreferences getsharedpreferences(context ctx){         return preferencemanager.getdefaultsharedpreferences(ctx);     }      public static void setuserpref(context ctx,string user_pref){         editor editor = getsharedpreferences(ctx).edit();         editor.putstring(user_pref,user_pref);         editor.apply();     }      public static string getuserpref(context ctx){         return getsharedpreferences(ctx).getstring(user_pref,"");     } } 

same thing device preferences ! , juste need access other class/activity/fragment :

mysharedpreferences.setuserpref(this /* or whatever context is*/,yourvalue); 

Comments