Search code examples
androidpreferencessharedpreferences

Use Preferences to get SharedPreferences


I had been using shared preferences to store some user values.... but when the nos of preferences started increasing. So i decided to use PreferenceActivity.

My problem is i want my prefeneceActivity to use my earlier sharedpreferences. Have already done the code for shared prefeneceActivity but just couldn't get option to use sharedpreferences.


Solution

  • Use

    SharedPreferences pref= Context.getSharedPreferences("SomePreferences", Context.MODE_PRIVATE);
    

    to Get SharedPreferences, and

    pref.getString(), pref.getInt()..../
    

    to get valuies from preferences.

    and load these values to PreferenceActivity's components.