7

It is often nice to have some default values in Shared Preferences to begin with. Is there a good way to initialize them from an xml file or property file? Looking for the best way to do this. Thanks.

Androider
  • 21,125
  • 36
  • 99
  • 158
  • possible duplicate of [Android Preferences: How to load the default values when the user hasn't used the preferences-screen?](http://stackoverflow.com/questions/2691772/android-preferences-how-to-load-the-default-values-when-the-user-hasnt-used-th) – Patrick Boos Aug 13 '14 at 09:13

2 Answers2

8

Read the answer in this question:

Android Preferences: How to load the default values when the user hasn't used the preferences-screen?

Community
  • 1
  • 1
Patrick Boos
  • 6,789
  • 3
  • 35
  • 36
0
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Make sure default values are applied.  In a real app, you would
        // want this in a shared function that is used to retrieve the
        // SharedPreferences wherever they are needed.
        PreferenceManager.setDefaultValues(getActivity(),
                R.xml.advanced_preferences, false);

}
Dan Alboteanu
  • 9,404
  • 1
  • 52
  • 40