Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 10. Handling and Persisting Data > The Android Database Classes

10.5. The Android Database Classes

This section introduces the Java classes that give you access to the SQLite functions described earlier in the chapter, with the data-centric model we just described in mind:


SQLiteDatabase

Android’s Java interface to its relational database, SQLite. It supports an SQL implementation rich enough for anything you’re likely to need in a mobile application, including a cursor facility.


Cursor

A container for the results of a database query that supports an MVC-style observation system. Cursors are similar to JDBC result sets and are the return value of a database query in Android. A cursor can represent many objects without requiring an instance for each one. With a cursor, you can move to the start of query results and access each row one at a time as needed. To access cursor data, you call methods named as Cursor.getAs*(int columnNumber) (e.g., getAsString). The values the cursor will return depend on the current cursor index, which you can increment by calling Cursor.moveToNext, or decrement by calling Cursor.moveToPrevious, as needed. You can think of the current index of the cursor as a pointer to a result object.

Cursors are at the heart of the basis for Android MVC, which we will cover in detail in Chapter 12.


SQLiteOpenHelper

Provides a life cycle framework for creating and upgrading your application database. It’s quite helpful to use this class to assist with the critical task of transitioning the data from one version of an application to a possible new set of database tables in a new version of an application.


SQLiteQueryBuilder

Provides a high-level abstraction for creating SQLite queries for use in Android applications. Using this class can simplify the task of writing a query since it saves you from having to fiddle with SQL syntax yourself.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial