Question

I am trying to work out the best practice for accessing SharedPreferences. Should they ALWAYS be accessed through the PreferenceManager? And can they ONLY be read and written to via the UI thread?

Any pointers or links to where I can read about this would be greatly appreciated. I have already looked at these links but I do not fully understand the reasoning behind the answers.

Android SharedPreferences Best Practices

Should accessing SharedPreferences be done off the UI Thread?

Thanks

Was it helpful?

Solution

    public boolean getPrefs()
{


      prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); 


      PREF1 = prefs.getBoolean("pref1_key",pref1_default);
      PREF2 = prefs.getString("pref2_key","pref2_default");


 }

use this method to get all preferences you need. Call this in the onResume() or onCreate() method. You needn't worry about UI or anything

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top