As a complete application, data storage operations are essential. Therefore, the Android system provides four data storage methods. They are SharePreference, SQLite, Content Provider, and File. In Android, data is basically private and stored in the "data/package name" directory. Therefore, to share data, use Content Provider. SQLiteSQLite is a lightweight database that supports basic SQL syntax and is a common data storage method. Android provides a class named SQLiteDatabase for this database, which encapsulates APIs for database operations. SharedPreferenceIn addition to the SQLite database, another common data storage method is essentially an xml file, which is often used to store simple parameter settings. FileThat is to say, the file (I/O) storage method is often used to store a large amount of data, but the disadvantage is that updating data will be difficult. ContentProviderA data storage method that can be shared by all applications in the Android system. Because data is usually private among applications, this storage method is rarely used, however, it is an essential storage method. For example, audio, video, image, and address book can be stored in this way. Each Content Provider provides a public URI (encapsulated as a Uri object). If the application needs to share data, the Content Provider needs to define a URI for the data, then other applications pass in the URI through the Content Provider to operate the data. PS: URI consists of three parts: "content: //", data path, and ID (optional ). |