Using sharedpreferences to record data in Android is like using an INI file to record data in computer software development. It just makes some simple records, such, whether the software starts an operation automatically or not, but the file format is XML, the content is as follows:
<? XML version = "1.0" encoding = "UTF-8" standalone = "yes" ?> - < Map > < Boolean Name ="
Isautorun " Value ="
True " /> </ Map >
This file can be read and parsed directly using sharedpreferences, read as follows:
Sharedpreferences preferces = getpreferences (activity. mode_private );
Isautorun = preferces. getboolean ("isautorun", true); tv1.settext (string. valueof (isautorun ));
Write as follows:
Sharedpreferences preferences = getpreferences (activity. mode_private );
Sharedpreferences. Editor editor = preferences. Edit ();
Editor. putboolean ("isautorun ",! Isautorun );
Editor. Commit ();
AboveCodeTested!