The Android platform provides us with a sharedpreferences class, which is a lightweight storage class that is especially suitable for saving software configuration parameters. Use Sharedpreferences to save the data, behind it is the XML file to hold the data, the file is stored in the/data/data/<package name>/shared_prefs directory:
Store:
Sharedpreferences sp=getsharedpreferences ("UItest", activity.mode_append);
Sharedpreferences.editor Editor=sp.edit ();//Get Editor
Editor.putstring ("Name", Edt1.gettext () + "");
Editor.putstring ("Xuehao", Edt2.gettext () + "");
Editor.putstring ("Zhuanye", Edt3.gettext () + "");
LOG.I ("Mainactivity", rb1.ischecked () + "value");
Editor.putboolean ("Xingbie", rb1.ischecked ());
Editor.commit ();
Getsharedpreferences ("name", "model");
The second parameter model has four modes:
Context.mode_private: The default mode of operation, which means that the file is private and can only be accessed by the app itself, in which the contents of the original file are overwritten.
Context.mode_append: The mode checks whether the file exists, appends content to the file, or creates a new file.
Context.mode_world_readable: Indicates that the current file can be read by another application;
Context.mode_world_writeable: Indicates that the current file can be written by another application.
Disadvantages and parameter meanings:
Only these basic types can be stored:
Editor.putstring ("String Name", "String Value");//String
Editor.putboolean ("String name", "Boolean value");//Boolean
Editor.putint ("String name", "int value");//integral type
Editor.putfloat ("String name", "float value");//floating-point
Editor.putlong ("String name", "Long Value");//Long Integer
Editor.putstringset ("String name", "set<string> value");
Get:
Sharedpreferences sp=getsharedpreferences ("UItest", activity.mode_append);
Sp.getstring ("name", null);//The corresponding value is taken out according to the key, the second parameter represents, when the folder does not have this key default return value is what, the current return empty, the other several are the same
Sharedpreferences of how Android data is stored