1, preferences can be used to persist user settings, game highest score, etc.
2, preferences have, list preferences, check box Preferences, dialog Preferences: 3, creating preferences through XML files and code Addpreferencesfromresource (R.xml.main) 4. Get values from preferencesResources Resources =
This. Getresources ();sharedpreferences spf= Preferencemanager.
getdefaultsharedpreferences (
This);String option = spf.getstring (resources.getstring (r.string.
Flight_sort_key),resources.getstring (r.string.
Flight_sort_default_value )); string[] Optionarray = Resources.getstringarray (r.array.
filght_sort_option );5. Determine if there is a value for a preference Boolean haspreferences = Myprefs.getboolean (INITIALIZED, false);
if (haspreferences) {
LOG.V ("Preferences", "We ' ve been called before");
Read other values as desired from preferences file ...
somestring = myprefs.getstring ("somestring", "" ");
}
else {
LOG.V ("Preferences", "first time ever being called");
Set up initial values for what would end up
In the Preferences file
somestring = "some default value";
}
Later when ready-to-write out values6. Set the value of Preferences in codeEditor editor = Myprefs.edit ();
CHAPTER 13:working with Preferences and saving State 359
Editor.putboolean (INITIALIZED, true);
Editor.putstring ("somestring", somestring);
Write other values as desired
Editor.commit (); 7. Preferences can be nested, and parent-child relationships may exist. 8 General Steps A. Layout preferences in the XML file B. Create an activity to inherit from Preferenceactivity, and then pass Addpreferencesfromresource () Create a view C. Get and set values by appropriate methods
Android Learning 13 First options