Storing data in the Sharedpreferences
1, define the Sharedpreferences object, through the Getsharedpreferences method to get
Sharedpreferences sp = getsharedpreferences (file name, mode);//mode is usually mode_private
2. Get editor editor for the Sharedpreferences object
Editor editor = Sp.edit ();
3. Store data in the Sharedpreferences via the editor
Editor.putxxx (field name, field value);//Field name is String, field value is consistent with XXX data type
4, editor commit data, complete data storage
Editor.commit ();
Get data from Sharedpreferences
1, define the Sharedpreferences object, through the Getsharedpreferences method to get
Sharedpreferences sp = getsharedpreferences (file name, mode);//mode is usually mode_private
2, directly through the Sharedpreferences object's GetXXX method obtains the data
XXX value = sp.getxxx (field name, default value);//Field name is string, default value for field name does not exist is the default value returned, default value data type is XXX
Android---------Access data using Sharedpreferences