Source Download (download points free): Download
Data collections for relatively few key-value pairs can be stored using sharedpreferences.
The data type of a key-value pair is basically a basic data type,
Common operations:
代码:
@Override protected voidOnresume() { Super.Onresume(); //Gets the Sharedpreferences object. sharedpreferencesprefs=getpreferences(0); //Read data from a shared preference StringStoredname=prefs.getString(USERNAME, NULL); if (Storedname!= NULL) {EditText.SetText(Storedname); } } @Override protected voidOnPause() { Super.OnPause(); //Get Sharedpreferences.editor object sharedpreferences.EditorEditor=getpreferences(0).Edit(); //Storage dataEditor.putstring(USERNAME,EditText.GetText().toString()); //Save corresponding change Number dataEditor.Commit(); }
Note: When you use Mode_world_readable and mode_worle_writeable when you create a shared preference, other programs can access the data
References:http://developer.android.com/training/basics/data-storage/shared-preferences.html
http://developer.android.com/guide/topics/data/data-storage.html