Android Data Storage Methods: What are the differences between sharepreference, SQLite, and contentprovider?

Source: Internet
Author: User

Android provides four data storage methods. Because Android data is basically privateProgramTo use the data, you must use the contentproviders provided by Android.

Four Data Storage Methods in Android:

Shared preferences

Similar to our commonly used INI files, this file is used to save some property settings of the application.

The platform is often used to store simple parameter settings. Data storage location: Directory:/data/<package>/shared_prefs/***. xml

We cannot share preferences data among multiple applications.

 

File Access (I/O)

Files are used to store a large amount of data using the I/O interface provided by the java. Io. * library to read and write files. Only local files can be accessed.

Advantage: it can store large data volumes.

Disadvantage: file update or format change may lead to huge programming work.

 

SQLite Database

SQLite is a lightweight software library with strong atomicity, independence, durability, and size. It only uses thousands of bytes. Some SQL commands are only partially supported, such as alter and table.

Android provides a class named sqlitedatabase, which encapsulates APIs for database operations. This class can be used to create, query, and update data) and delete operations (crud ).


Content Provider
Content Provider is a bridge between data storage and retrieval among all applications. Its function is to share data among various applications. Android provides contentprovider (including audio, video, image, and address book) for common data)

Each content providers will provide a public uri (packaged as a URI object). If the application needs to share data, you need to use content providers to define a URI for the data, then other applications can pass in this URI through content providers to operate the data. Uri consists of three parts: "content: //", data path, and Id (optional ).

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.