Android (5) data storage

1. Android data storage method

The five data storage methods provided by the Android platform are file storage, SharedPreferences, SQLite database, ContentProvider, and network storage. The characteristics of these storage methods are as follows.

(1) File storage

Android provides openFileInput() and openFileOutput() methods to read files on the device, and the reading method is exactly the same as the I/O program in Java.

(2) SharedPreferences

This is a mechanism provided by Android to store some simple configuration information. It uses XML format to store data in the device. Usually, we use SharedPreferences to store various configuration information of some applications , such as user name, password, etc.

(3) SQLite database

SQLite is a lightweight database that comes with Android. It has fast computing speed, takes up less resources, and supports basic SQL syntax. It is generally used as a storage engine for complex data , and can store user information.

(4) ContentProvider

One of the four major components of Android, mainly used for data exchange between applications , he can share his own data with other applications.

(5) Network storage

It needs to deal with Android network data packets, store data on the server, and store/obtain data information through the storage space provided by the network .

Two, the four basic elements of database things

The operation of the transaction is relatively strict. It must meet ACID. ACID refers to the abbreviation of the four basic elements for the correct execution of database transactions. These elements include Atomicity, Consistency, Isolation, and Persistence ( Durability), and then explain these four basic elements in detail.

(1) Atomicity

Indicates that a transaction is an indivisible unit of work, and the operations in the transaction either all succeed or fail and roll back.

(2) Consistency

Indicates that the integrity of the database has not been compromised before and after the transaction begins. That is to say, database transactions cannot destroy the integrity of relational data and the consistency of business logic.

(3) Isolation

Indicates that concurrent transactions are isolated from each other, that is, operations within a transaction must be blocked and will not be affected by other transactions.

(4) Persistence

It means that once the transaction is committed, the changes made by the transaction to the data will be permanently saved in the database and will not be rolled back. Even if there is an accident such as a power outage, the data in the database will not be affected.

Context.MODE_PRIVATE : It is the default operation mode, which means that the file is private data and can only be accessed by the application itself. In this mode, the written content will overwrite the content of the original file. If you want to append the newly written content to the original in the file. Can use Context.MODE_APPEND

3. File operation mode parameters

Context.MODE_APPEND

The mode checks to see if the file exists, appends to it if it exists, or creates a new file otherwise.

Context.MODE_WORLD_READABLE和Context.MODE_WORLD_WRITEABLE

Used to control whether other applications have permission to read and write the file.

MODE_WORLD_READABLE

Indicates that the current file can be read by other applications;

MODE_WORLD_WRITEABLE

Indicates that the current file can be written by other applications

Guess you like

Origin blog.csdn.net/qq_55691371/article/details/128064354