In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "what is the way data is stored in Android". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the way of data storage in Android?"
First: use SharedPreferences to store data
Scope of application: save a small amount of data, and the format of the data is very simple: string, basic type values. For example, various configuration information of the application (such as whether to turn on the sound effect, whether to use the vibration effect, Mini Game player points, etc.), unlock order password, etc.
Core principle: save key-value key-value pair data stored in XML files, which is usually used to store some simple configuration information. Through the File Explorer panel of DDMS, expand the file browse tree, and it is obvious that SharedPreferences data is always stored in the / data/data//shared_prefs directory. The SharedPreferences object itself can only obtain data and does not support storage and modification, which is implemented through the internal interface Editor object obtained by SharedPreferences.edit (). SharedPreferences itself is an interface, and the program cannot create a SharedPreferences instance directly. You can only obtain the SharedPreferences instance through the getSharedPreferences (String name, int mode) method provided by Context. In this method, name represents the name of the xml file to be operated. The second parameter is as follows:
Context.MODE_PRIVATE: specifies that the SharedPreferences data can only be read and written by this application. Context.MODE_WORLD_READABLE: specifies that the SharedPreferences data can be read by other applications, but not written. Context.MODE_WORLD_WRITEABLE: specifies that the SharedPreferences data can be read and written by other applications
Compared with SQLite database, SharedPreferences object eliminates many operations, such as creating database, creating table, writing SQL statement, etc., which is relatively more convenient and concise. But SharedPreferences also has its own shortcomings, such as its function to store five simple data types of boolean,int,float,long and String, such as its inability to make conditional queries. Therefore, no matter how simple the data storage operation of SharedPreferences is, it can only be a supplement to the storage mode, and can not completely replace other data storage methods such as SQLite database.
The second type: file storage data
You can create files to hold data in the storage device of the device itself or in an external storage device. Also by default, files cannot be shared between different programs.
Write file: call the Context.openFileOutput () method to create a file based on the specified path and file name, which returns a FileOutputStream object.
Read the file: call the Context.openFileInput () method to return a standard Java FileInputStream object with the specified path and file name.
The third kind: SQLite stores data
SQLite Database database. Android supports the database very well, it integrates the SQLite database itself, and every application can use it conveniently, or more precisely, Android completely depends on the SQLite database, and all its system data and structured data are stored in the database. It has the following advantages: a. It is undeniable that the efficiency is excellent. Very suitable for storing structured data c. It is convenient to transfer data between different Activity and even different applications.
The fourth kind: ContentProvider
A data storage method that can be shared by all applications in Android system. Because the data is usually private among applications, this storage method is seldom used, but it is also an indispensable storage method. For example, audio, video, pictures and address books can generally be stored in this way. Each ContentProvider will provide a public URI (wrapped as a Uri object). If the application has data to share, it needs to use ContentProvider to define a URI for the data, and then other applications will pass in the URI through ContentProvider to manipulate the data.
At this point, I believe you have a deeper understanding of "what is the way data is stored in Android". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.