Android Development: Sharedpreferences store data, get data

Source: Internet
Author: User

Android Development: Sharedpreferences store data, get data

Email:[email protected]

Development Environment : Win7 64-bit,Android Studio.

About Sharedpreferences. Personal understanding of it is understood as a lightweight database. The Access form is the same as map: <key,value>, stored as an XML file.

I just use it to store the login information and login status so that I can read the information locally every time I log in.

A. Storage

/**                             * Save personal information locally *                            /sharedpreferences sharedpreferences = getsharedpreferences ("Intveh", Context.mode_ PRIVATE);                            Sharedpreferences.editor editor = Sharedpreferences.edit ();//Get editor                            //should also record user_id                            editor.putstring (" UserID ", userid);                            Editor.putstring ("Phone", userphone);                            Editor.putstring ("password", userpassword);                            Log Login Status                            editor.putstring ("status", "1");                            Editor.commit ();//Submit Changes

Two. Read

Sharedpreferences sharedpreferences = getsharedpreferences ("Intveh", activity.mode_private);                String userId = sharedpreferences.getstring ("userid", "");                String status = sharedpreferences.getstring ("status", "0");

Please note: sharedpreferences.getstring ("Key", "default value returned when key does not exist").

Many other about sharedpreferences, can participate: http://www.cnblogs.com/linjiqin/archive/2011/05/26/2059133.html


Android Development: Sharedpreferences store data, get 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.