Data stored in android

android the data stored in several ways discussed briefly :()

1. File
Example: landing "Remember Password"
Because it is based on the Linux system, built directly file, the file will appear in the project; while the phone is logged in a file should be on the phone, usually the data on the data / data / package name /info.txt
Convenient API:
context: the context
context.getFilesDir(); // data/data/<包名>/files/
context.getCacheDir(); // data/data/<包名>/cache/
 
context.openFileInput ( "info.txt"); // corresponds to quickly get the input stream
File filedir = context.getFileDir();
File file = new File(filedir,"info.txt");
FileInputStream fis = new FileInputStream(file);
 
 
context.openFileOutput ( "info.txt", mode); // get the output stream Fast
There are many parameters mode fixed values: WorldReadable ....
 
File mode under Linux: "-" indicates that the file, "d" indicates a directory
”-  rw-  ---   ---  “:
rw-: represents the current user access to files, and the third parameter indicates whether an executable file
The latter two "---": representing the current user's group permissions and other user rights, parameters can also be a "r -, rw -...."
Available chmod + "666" + filename change under linux command line access to their rights, "666" stands for: "- rw- (110,7) rw- (110,7) rw- (110,7)"
 
In Android, App by default each user is an individual, with its own unique user ID, you can say that every App is a secure sandbox, you can set whether it has exposed file information
 
The files on the SD card :( obtain the directory SD card)
You need to configure the SD card write access to the file in manifest.xml
Method Environment.getExternalStorageState ();
...
 
Regardless of the documents on the phone itself or SD card, first check whether you put enough storage space to save the file? (Acquisition system comes with a free space, direct reference source code (Eclipse in use ctrl + H stepwise search key character string system application))
 
2.SharedPreference (parameters)
Timing for data update and save content, such as 5s updated on the website
Timer, TimerTask (override the run method), Timer.schedule
this.getSharedPreferences(); Editor SharedPreferences.edit();
editor.putString();editor.getString();...
SharedPreference to save the data stored by the data content to a new xml file, the file is directed to a similar I / O operation
 
(to be continued...)
3.SQLite database
1) write a database to help open classes, inheritance sqliteOpenHelper
2) oncreate help class override method, initialize the database table structure
3) use OpenHelper get database, execute SQL statements
 
4. Content provider Content provider
 
5. Network

Reproduced in: https: //www.cnblogs.com/allenpengyu/p/3581374.html

Guess you like

Origin blog.csdn.net/weixin_34061555/article/details/94507585