Android Database Support
WHAT’S IN THIS CHAPTER?
- Learning about SQL support in Android
- Understanding SQL from Java: The SQLiteDatabase class
- Creating a database: The SQLiteOpenHelper class
- Understanding loaders, cursors, and adapters
WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
Please note that all the code examples in this chapter are available at https://github.com/wileyenterpriseandroid/Examples.git and as a part of the book’s code download at www.wrox.com on the Download Code tab.
The previous chapter introduced SQLite and demonstrated its use from a command line on the Android platform. This chapter extends the demonstration to show the use of SQLite from an application.
In order to use local, structured data from an application, it is necessary to do several things:
- Embed SQL commands in application code and execute them at run time.
- Create, initialize, and update databases as needed.
- Select a database lifecycle management strategy appropriate for an application.
- Parse the data obtained from queries for use in an application.
SQL IN JAVA: THE SQLITEDATABASE CLASS
Chapter 2 demonstrated the use of SQLite from the command line. In order to be useful as part of an application, however, it must be possible to embed SQL in the Java code that composes an application. The Android library provides the SQLiteDatabase class for this purpose.
Running SQL queries against a SQLite database, from Java code, requires an instance of the SQLiteDatabase class. You’ll see in the next ...