Introduction to 1.Android Databases
Android provides durable functionality for structured data by using a combination of SQLite database and content Provider.
SQLite databases can store application data in a structured, easy-to-manage way. Android provides a complete library of SQLite relational database files. Each application can create its own database and have full control over the database.
The android database is stored in the/data/data/<package name>/database folder on the device, and all the databases are private and can only be accessed by the application that created them.
2.Content Provider Introduction
Content provider provides an interface for publishing and using data based on a simple URI addressing model using the "content://" pattern, one of the four components of Android.
Once you have created the underlying data store, you can use the content Provider, which performs a consistent abstraction through the underlying data source, so that the application does not have to rely too much on a data source.
Use it to share data between applications, such as when our app can get text messages or contact actions. Of course we can also publish our own content Provider so that others can crud our database in their application.
The specific use method, later will have the topic to introduce.
3.SQLite Introduction
SQLite is a popular relational database management system (relational). Features: Open source conforms to standard lightweight. It has been implemented as a concise C language and has become part of the Android software stack.
Each SQLite database becomes the complete part of the application that created it, by implementing it as a library instead of being executed as a separate process. Doing so reduces the external dependencies of the application, minimizes latency, and simplifies transaction locking and synchronization.
SQLite is very reliable and is the preferred database system for many consumer electronics products, such as many MP3 players and smartphones.
4.Content Value and cursor
Content value is used to insert a new row into a table in the database. Each of the Contentvalues objects represents a table row as a column name to be worth mapping.
The database query is returned as a cursor object. The cursor is a pointer to the result set in the underlying data, and he does not fetch and return the result worth a copy.
Common methods of cursor:
Cursor.movetofirst ();//move the cursor to the first row in the query result cursor.movetonext ();//move the cursor to the next line cursor.movetolast ();// Move the cursor to the last row cursor.movetoprevious ();//move the cursor forward one line cursor.getcount ();//Get the number of result sets Cursor.getcolumnindexorthrow ("");//returns its index according to the specified column name, starting with 0, without throwing an exception cursor.getcolumnnames ();// Gets the string data for all column names in the current cursor cursor.getcolumnname (1);//returns the column name cursor.movetoposition (1) based on the index;//moves the cursor to the specified row Cursor.getposition ();//Gets the position of the current cursor
5.SQLiteOpenHelper Introduction
Sqliteopenhelper is an abstract class that enables you to create, open, and upgrade databases.
Sqliteopenhelper will cache the DB instance after it has been successfully opened, so we can request to open the database before the query or transaction is executed, unless we no longer need to use the database, and we don't need to shut them down manually.
Database operations, especially when opened and created, take a long time to complete, so in order to ensure that these operations do not affect the user experience, database operations should be performed asynchronously.
In general, in our application we need to define a class to inherit the Sqliteopenhelper class, and by overriding its constructor OnCreate Onupgrade method to process the creation of the database and the upgrade to the new version of the database separately.
Some of the basic concepts of the database is briefly introduced to this, the next combat code to introduce the Android database additions and deletions to change the operation.
Basic Concepts of Android database (top)