Created
May 3, 2009 23:51
-
-
Save prasincs/106207 to your computer and use it in GitHub Desktop.
get the default preferences in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Put this in the starting activity to declare the default values. | |
PreferenceManager.setDefaultValues(this, R.xml.posit_preferences, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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