O'Reilly logo

Enterprise Android: Programming Android Database Applications for the Enterprise by Zane Pan, Laird Dornin, G. Blake Meike, Zigurd Mednieks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required