The Sharedpreferences object obtained by invoking the Getsharedpreferences () method of the context object can be shared by other components under the same application.
The Sharedpreferences object obtained by the
(3) Sharedpreferences () property, including four modes.
3.1, Context.mode_private: The default mode of operation, representing the file is a private file, can only be used by the application itself to ask. Writing to a file in this mode overwrites the original file contents
3.2, Context.mode_append: This mode checks whether the file exists, appends content to the file, or creates a new file.
3.3, context.mode_world_readable: Indicates that the current file can be read by another application.
3.4, context.mode_world_writeable: Indicates that the current file can be written by another application.
(4)
Sharedpreferences preferences=getsharedpreferences ("user", context.mode_private); Editor Editor=preferences.edit (); String name= "Xixi"; String age= "editor.putstring" ("Name", "name"), Editor.putstring ("age", age); Editor.commit ();
(5)getting data from Sharedpreferences
Sharedpreferences preferences=getsharedpreferences ("user", context.mode_private); String name=preferences.getstring ("name", "DefaultName"); String age=preferences.getstring ("Age", "0");
Specific explanations for sharedpreferences functions in Android