In Android, there are several data storage methods, such as file storage and file database storage. Android comes with an SQLite database, embedded developers are not familiar with this cross-platform local file database.
In Android, a new method is proposed for data access. The ContentProvider method is similar to the ContentProvider method of MS, OLEDB, and ODBC unified data mode. First, let's take a look at the use of SQLite in Android. The simplest way to use it in Android is to use openorCreateDatabase of the Context object. Let's take a look at a piece of code:
- Private String getName ()
- {
- String name = null;
- Cursor cur = this. getContentResolver (). query (ProviderConst. MY_TEST_URI, new String [] {"id", "name"}, null );
- If (cur = null)
- Return null;
- Cur. moveToFirst ();
- Do
- {
- Namename = name + cur. getString (1) + "\ n ";
- } While (cur. moveToNext ());
- Return name;
- }
- We can also use:
- Private String getName ()
- {
- String name = null;
- Cursor cur = this. managedQuery (ProviderConst. MY_TEST_URI, new String [] {"id", "name"}, null );
- If (cur = null)
- Return null;
- Cur. moveToFirst ();
- Do
- {
- Namename = name + cur. getString (1) + "\ n ";
- } While (cur. moveToNext ());
- Return name;
- }
We have understood the simple usage method, so let's analyze the complicated content.