One of the simplest Android data persistence methods is to use the key-Value Pair storage method of preferences. This method is mainly used to store relatively simple data,
It is a standard Boolean, Int, float, long, string, and other types.
Android. content. sharedpreferences is an interface used to obtain and modify persistent storage data.
There are three ways to obtain persistent data stored in the system:
1. This. getpreferences (INT Mode)
The preference of the activity is obtained through the activity object. The name of the XML file stored in the system is the name of the activity. Therefore, only one activity can have one preference, belongs to this activity.
2. This. getsharedpreferences (string name, int Mode)
Because activity inherits contextwrapper, it is obtained through the activity object. However, it belongs to the entire application and can have multiple objects. The name of the first parameter is saved as the file name in the system.
Obtain this. getsharedpreferences ("name", null );
3. preferencemanager. getdefasharsharedpreferences (this );
The static function of preferencemanager saves the settings in preferenceactivity, which belongs to the entire application. However, only one static function, Android saves a name based on the package name and preferenceactivity layout file.
For example:
Sharedpreferences prefs = preferencemanager. getdefasharsharedpreferences (context );
Prefs. Edit (). putstring ("userid", userid). Commit ();
Prefs. Edit (). putstring ("name", name). Commit ();
Get preferencemanager. getdefasharsharedpreferences (context). getstring ("nikename ","");
Reference: http://blog.csdn.net/zxmlovena/article/details/7394096