I have 3 - 4 Activities. One of those is the main activity and a second one is a Preference Screen. I have a preference screen with different Preferences like ListPreference etc that have default values.
How can i activate default Value of Settings when I start my project?
By default, they activate only when I start the Settings Activity. Shortly: I need to use the default value in the main activity without calling the Settings Activity.
What I do is have a static method in my Preferences activity class, so it can be called from anywhere:
static public boolean getOrderByDate(Context context) {
SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("order_by_date", true);
}
Note that my default value (true) is specified here in the getBoolean() call. If you want all the defaults specified in one place, you might need to call Preference.setDefaultValue() rather than setting it in the XML.