Android: The sharepreferences of storage mode

Source: Internet
Author: User

Using Sharedpreferences to save data, the essence is to use the XML file to store data,

Storage location:/data/data/<package name>/shared_prefs

Write:

   PublicvoidWriteData (view view) {// Instantiate the Sharedpreferences object, parameter 1 is the name of the stored file, parameter 2 is the way the file is opened, and when the file does not exist, it is created directly, and if it exists, it is directly used Sharedpreferences mysharepreferences =getsharedpreferences ("test"  Activity.mode_ PRIVATE); // Instantiate Sharedpreferences.editor Object Sharedpreferences.editor Editor =mysharepreferences.edit (); // save data putstring with editor.putstring ("name", " tinyphp "); // submit data  Editor.commit ( ); // hint successful Toast.maketext ( this, "data is successfully written to"   

Mode is default to 0 or mode_private
Mode_private, read only, accessible only by its own application
Mode_world_readable, readable, in addition to their own access can also be read by other programs should be
Mode_world_writeable, can be written, in addition to their own access can also be read by other programs and write

Read:

void ReadData (view view) {        // Instantiate Sharedpreferences object        sharedpreferences myshareperferences = Getsharedpreferences ("Test"// getString Gets the value String name =myshareperferences.getstring ("name", ""// Show Toast.maketext (This, "read data \ n" + "name:\n" +name, Toast.length_short). Show ();    

Related articles:

Control Autocompletetextview Client Save search History auto Prompt

Android: Sharepreferences of storage method

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.