Chapter 8. Persistent Data Storage: SQLite Databases and Content Providers

To accomplish many of the activities offered by modern mobile phones, such as tracking contacts, events, and tasks, the operating system and applications must be adept at storing and keeping track of large quantities of data. Most of this data is structured like a spreadsheet, in the form of rows and columns. Each Android application is like an island unto itself, in that each application is only allowed to read and write data that it has created, but sharing data across application boundaries is necessary. Android supports the content provider feature mentioned in Chapter 1 so that applications can share data.

In this chapter we examine two distinct data access APIs that the Android framework offers:

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.

ContentProvider

An interface used between applications. The server application that hosts the data manages it through basic create, read, update, and delete (CRUD) operations. The client application uses a similar API, but the Android framework transmits the client’s requests to the server. We’ll show both the server API and the client API in this chapter.

Databases

Data is best stored in a relational database format if it can include many instances of the same type of thing. Take a contact list, for instance. ...

Get Android Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.