This chapter presented the basic API for working with databases in Android and built upon the concepts introduced in Chapter 4, “SQLite in Android,” where database creation was discussed. By using SQLiteDatabase and its create(), insert(), update(), replace(), and delete() methods, an app is able to manipulate an internal database. In addition, an app can call the query and rawQuery() methods to retrieve the data from a database to perform actions on that data, or just display it to a user.
Query data is returned in the form of a cursor that can be iterated over to access the result set returned by a query.
While this chapter introduced some of the low-level “plumbing” needed to use an in-app database, there are higher-level components that allow apps to both abstract some of the data access details away from components that define and drive user interaction (activities and fragments) as well as allow data to be shared across apps and across processes. These concepts are introduced in the next chapter with the discussion of content providers.