Android app Development sharedpreferences How to use stored data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.