Course Objectives:
Several ways to master data storage in Android
Proficient in using Preferenceactivity&preferencescreen to do professional setting function
Proficient in using SQLite3 to store data
In-depth study of SQLite3 database features, and compared to large databases including stored procedures, the main foreign key association and other characteristics
Learn about the internal and external storage of file storage understand the principle of network storage C/s structure separately.
Key difficulties: features of the Sqliteopenhelper class using the SQLite database
Assessment objectives:
Say several forms of Android data storage?
Can the Sqlite3 support the stored procedure and support the primary foreign key association?
How to integrate your setting program with the setting program of the system
First, the study of Android data storage
XML Share Preference
Binary file file < Using internal storage, using extended storage >
relational database SQLite3
Web Access network <socket, http,https>
Second, sharedpreference
2.1 Basic Operation steps
1) getsharedpreference
2) Get Sharedpreferences.editor
3) Editor.commit ().
2.2 Three ways to get preference difference
1) public sharedpreferences getpreferences (int mode)
The activity object obtains, obtains is this activity private preference, the file which saves in the system the XML form the name is this activity's name, therefore one activity can only have one, belongs to this activity.
2) Public sharedpreferences getsharedpreferences (String name, int mode)
Because activity inherits the Contextwrapper, it is also obtained through the activity object, but belongs to the entire application, can have more than one, with the name of the first parameter is saved in the system.
3) public static sharedpreferences Getdefaultsharedpreferences (context context)
Preferencemanager static functions, saving the settings in the preferenceactivity, belong to the entire application, but only one, Android will be based on the package name and preferenceactivity layout file to save a name.
2.3 Creating a professional user Preference
Preferenceactivity
Preferencescreen.
. Setonpreferencechangelistener ...
2.4 How to nest systems preference
2.5 subtopic
Third, SQLite3
3.1 SQLite Database Introduction
SQLite (http://www.sqlite.org/), is a lightweight database, is an acid-compliant relational database management system, it is designed to be embedded, and currently used in many embedded products, it occupies a very low resource, in embedded devices, It may only take hundreds of K of memory to be sufficient. It can support Windows/linux/unix and so on mainstream operating system, and can be combined with many programming languages, such as TCL, C #, PHP, Java, and ODBC interface, also compared to MySQL, PostgreSQL, the two open source world-renowned database management system, is processing faster than they do. The first alpha version of SQLite was born in May 2000. So far there have been 10 years, SQLite also ushered in a version of SQLite 3 has been released.
Features: Lightweight, independent, isolated, cross-platform, multi-lingual interface, security.
3.2 Summary
SQLite is a full-fledged file-based database that supports SQL statements
Sqlite supports transactions, views, indexes, triggers, primary foreign KEY constraints
The default must give each table the primary key name _id
Sqlitedatabase can be used in the encapsulated INSERT, UPDATE, delete, Query method, you can also use Execsql, Rawsql and other native methods
3.3 Sqliteopenhelper
Getreadabledatabase ()
Getwritabledatabase ()
OnCreate (sqlitedatabase db, int oldversion, int newversion)
OnOpen (Sqlitedatabase db)
Onupgrade (Sqlitedatabase db)
1) through helper, set up database table structure-onCreate, Onupgrade.
2) Call the helper instance and get the DB object through Get***database ().
3) Use DB object instance to invoke additions and deletions, insert ().
3.4 Setting up the database, updating the database: adb shell look at the database
3.5 Specific data operations: Add,update,search,delete, batch update and delete.
3.6 Let's think about where the Sqlite3 database engine is. External/sqlite
Ideas:
If you come to transplant, open source project, you are compiled good class library put up or direct source is put up?
If the source code up, we go to the official website to download the source, open to see
Go search the source code.
Locate the address.
3.7 Let's think about the SQlite3. What is the actual connection method? Libcore/sqlite-jdbc
3.8 Primary foreign key relationships for tables
3.9 View of the table
3.10 Tables of triggers, stored procedures
3.11 SQLite Transaction
BeginTransaction
Settransactionsuccessful
Endtransaction
10. Android Data storage