Best Practice: SharedPreferences

![Thumbnail][7]

[Article source on github][6]

Android provides many ways of storing application data. One of those ways leads us to the SharedPreferences object which is used to store private primitive data in key-value pairs.

All logic are based only on three simple classes:

  • [SharedPreferences][1]
  • [SharedPreferences.Editor][2]
  • [SharedPreferences.OnSharedPreferenceChangeListener][3]

Sorry this site is not supported any more. This article has moved to http://blog.yakivmospan.com/best-practices-for-sharedpreferences/

3 thoughts on “Best Practice: SharedPreferences

  1. Pingback: android | Annotary
  2. Merci, thank you, the Performance part is what I was looking for 😉
    It’s nice that SharedPreference is a singleton and we can read a lot of properties quickly.

  3. Example :
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String s = prefs.getString(getString(R.string.pref_theme), “1”);

    Question: if a good thing – to parse “key” from xml strings (R.string.pref_theme – at this point).
    I do that, because i use PreferenceFragment with same key, and don’t want to write “pref_theme” key twice… (on xml/preference.xml and like: private static final String PREF_THEME = “pref_theme” )
    What about performance, logic, etc ?

Leave a comment