Sharedpreferences is the easiest data storage technology to understand in Android, and in fact sharedpreferences is dealing with a key-value (key-value pair) Sharedpreferences used to store some lightweight data.
Use Sharedpreferences to save data, behind it is to use XML files to store data, files stored in the/data/data/<package name>/shared_prefs directory
/*** Package for sharepreference * *@authorKevin **/ Public classPrefutils { Public Static voidPutboolean (String Key,Booleanvalue, Context ctx) {Sharedpreferences SP= ctx.getsharedpreferences ("config", context.mode_private); Sp.edit (). Putboolean (key, value). commit (); } Public Static BooleanGetboolean (String Key,Booleandefvalue, Context ctx) {Sharedpreferences SP= ctx.getsharedpreferences ("config", context.mode_private); returnSp.getboolean (key, defvalue); } Public Static voidputstring (string key, String value, Context ctx) {sharedpreferences SP= ctx.getsharedpreferences ("config", context.mode_private); Sp.edit (). putstring (key, value). commit (); } Public Staticstring getString (String key, String defvalue, Context ctx) {sharedpreferences SP= ctx.getsharedpreferences ("config", context.mode_private); returnsp.getstring (key, defvalue); } Public Static voidPutint (String Key,intvalue, Context ctx) {Sharedpreferences SP= ctx.getsharedpreferences ("config", context.mode_private); Sp.edit (). Putint (key, value). commit (); } Public Static intGetInt (String Key,intdefvalue, Context ctx) {Sharedpreferences SP= ctx.getsharedpreferences ("config", context.mode_private); returnsp.getint (key, defvalue); } Public Static voidRemove (String key, Context ctx) {sharedpreferences SP= ctx.getsharedpreferences ("config", context.mode_private); Sp.edit (). Remove (key). commit (); }}View Code
Prefutils.putboolean ("Is_guide_show", true, this);
Determine if you need to jump to novice boot
Boolean isguideshow = Prefutils.getboolean ("Is_guide_show",
False, Getapplicationcontext ());
Android app Development sharedpreferences How to use stored data