Use of sharepreference in Android

Source: Internet
Author: User


Android has four methods:


Sharepreference
Lightweight key-value storage, saved as an XML file.
File
Use the I/O interface provided by the java. Io. * library to read and write files.
Sqls Database
SQLite is a lightweight embedded database.
Contentprovider
Contentprovider can encapsulate data and share data with multiple applications.

 


Create sharepreference

Sharedpreferences settings = This. getsharedpreferences ("testxml", 0 );
Sharedpreferences. Editor localeditor = settings. Edit ();

// The a_map03 class must inherit the subclass of activity to have the getsharedpreferences method.

Add data as a key value <string key, string value>

Localeditor. putboolean ("shownote", false );
Iocaleditor. Commit ();

Use string key as the index to retrieve data

String STR = settings. getstring ("shownote ","");

Clear Data

Localeditor. Clear (). Commit ();

The sharedpreferences data is stored in:
Content stored in XML
Directory:/data/<package>/shared_prefs/***. xml

Related Article

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.