Using Sharedpreferences to save data, the essence is to use the XML file to store data,
Storage location:/data/data/<package name>/shared_prefs
Write:
PublicvoidWriteData (view view) {// Instantiate the Sharedpreferences object, parameter 1 is the name of the stored file, parameter 2 is the way the file is opened, and when the file does not exist, it is created directly, and if it exists, it is directly used Sharedpreferences mysharepreferences =getsharedpreferences ("test" Activity.mode_ PRIVATE); // Instantiate Sharedpreferences.editor Object Sharedpreferences.editor Editor =mysharepreferences.edit (); // save data putstring with editor.putstring ("name", " tinyphp "); // submit data Editor.commit ( ); // hint successful Toast.maketext ( this, "data is successfully written to"
Mode is default to 0 or mode_private
Mode_private, read only, accessible only by its own application
Mode_world_readable, readable, in addition to their own access can also be read by other programs should be
Mode_world_writeable, can be written, in addition to their own access can also be read by other programs and write
Read:
void ReadData (view view) { // Instantiate Sharedpreferences object sharedpreferences myshareperferences = Getsharedpreferences ("Test"// getString Gets the value String name =myshareperferences.getstring ("name", ""// Show Toast.maketext (This, "read data \ n" + "name:\n" +name, Toast.length_short). Show ();
Related articles:
Control Autocompletetextview Client Save search History auto Prompt
Android: Sharepreferences of storage method