Original address
Storage location
sharedpreferences data saved: /data/data/<package_name>/shared_prefs directory, stored in XML format, the root element is: <map/>. The file name is the parameter value passed when getting the sharedpreferences instance.
<map><int name= "key" value= "value"/><string name= "key" > Value </string></map>
Get instance
shareperferences is an interface, the Context implements the Api:getsharedpreferences (string, int); This API returns a Shareperferences instance based on a string. The same string returns an instance of Shareperferences that is the same. Here strign specifies the name of the XML file where the data is stored.
Activity implements getpreferences (int), which is the default use of activity's class name as a string called getsharedpreferences (string, int).
Specifies that the sharedpreferences data can only be read and written by the application. Context.mode_private//Specifies that the Sharedpreferences data can also be read by other applications, but cannot be written. Context.mode_world_readable//Specifies that the Sharedpreferences data can also be read and written by other applications. The context.mode_world_writeable//file exists, so append is present, or new context.mode_world_append
Read
Write
sharedpreferences The interface itself does not provide the ability to write data, but through its internal interface. It calls the Sharedpreferences.edit () method to get the Sharedpreferences.editor object it corresponds to. The editor has the following methods for writing data to Sharedpreferences:
Empty all the data in the sharedpreferences. Editor.clear ()//to the sharedpreferences to deposit the data corresponding to the specified key. Editor.putxxx (String key, Xxx Value)//delete the data item corresponding to the specified key in Sharedpreferences. Editor.remove (String key)//When editor is finished, call the method to commit the modification. Boolean Editor.commit ()
Read and write sharedpreferences for other applications
1. Create the corresponding Context for the other app.
Context usecontext =createpackagecontext ("Package_name", context.context_ignore_security);
2. Call the Getsharedpreferences () method of the Context of the other app to get the Sharedpreferences object.
3. Call the Sharedpreferences.edit () method of the other app to get the corresponding Sharedpreferences.editor object.
Android Local Storage Solution Sharedpreferences