Skip to content

Instantly share code, notes, and snippets.

@prasincs
Created May 3, 2009 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasincs/106207 to your computer and use it in GitHub Desktop.
Save prasincs/106207 to your computer and use it in GitHub Desktop.
get the default preferences in Android
// to get the default preferences for an application assuming your preferences file is in
// res/xml/posit_preferences
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
Log.i(TAG, sp.getString("APP_KEY", "test"));
//Put this in the starting activity to declare the default values.
PreferenceManager.setDefaultValues(this, R.xml.posit_preferences, false);
//to edit the values from other application.
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = settings.edit();
editor.putString("APP_KEY", map.get("app_key").toString());
editor.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment