Writing to the Database

The first step in using your SQLiteDatabase is to write data to it. You will need to insert new rows into the crime table as well as update rows that are already there when Crimes are changed.

Using ContentValues

Writes and updates to databases are done with the assistance of a class called ContentValues. ContentValues is a key-value store class, like Java’s HashMap or the Bundles you have been using so far. However, unlike HashMap or Bundle it is specifically designed to store the kinds of data SQLite can hold.

You will be creating ContentValues instances from Crimes a few times in CrimeLab. Add a private method to take care of shuttling a Crime into a ContentValues. (Remember to use the same two-step ...

Get Android Programming: The Big Nerd Ranch Guide, 2nd Edition 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.