Android Data and Access (1)-Where do I put my app configuration parameters file?

Source: Internet
Author: User

The system provides data processing methods:

1, Sharedpreferences

2. File storage

3, the lightweight data. such as Sqllite

1. Simple Storage

Is the age-old data storage method that Android provides: Sharedperences. Save your data in the simplest way. It shields the underlying file operations and provides a simple program interface for the program staff to save data based on key words.

1.1SharedPreferences

General procedures need to configure parameters such as supporting data, under Windows is almost and EXE in a directory. When the program starts, it reads the parameter file, which changes the contents of the program. The Android app's parameter file is implemented via Sharedpreferences.

The format is: INI and XML, or a file of your own custom format.

Sharedpreferences provides a way to handle these three ways.

1.2 Access to three modes:

Mode_private; (Read and write only)

Mode_world_readable (Other people can read)

Mode_world_writeable (Other people can write)

Define access mode before access: public Staticint mode=mode_private;

Read/write mode mode=context.mode_world_readable+context.mode_world_writeable;

1.3 How to obtain an instance:

public static final String preference_name= "SaveSetting";

Sharedperferences sharedpreferences=getsharedpreferences (Preference,mode);

Sharedpreferences can be modified by class after 1.4

String name = sharedprefences.getstring ("name", John Doe ");

int age = Sharedprefences.getint ("Age", 21);

float height = sharedprefences.getfloat ("height", 1.80f);

Sharedpreferences.editor Editor = Sharedpreferences.edit ();

Editor.putstring ("Name", "usegear");

Editor.putint ("Age", 101);

Editor.putfloat ("Height", 1.81f);

Editor.commit ();

Call commit () to save the underlying data type, including Integer, Boolean, float, long, and so on.

Android Data and Access (1)-Where do I put my app configuration parameters file?

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.