DatabaseConnector Method insertContact

Method insertContact (Fig. 8.53) inserts a new contact with the given information into the database. We first put each piece of contact information into a new ContentValues object (lines 47–54), which maintains a map of key–value pairs—the database’s column names are the keys. Lines 56–58 open the database, insert the new contact and close the database. SQLiteDatabase’s insert method (line 57) inserts the values from the given ContentValues into the table specified as the first argument—the "contacts" table in this case. The second parameter of this method, which is not used in this app, is named nullColumnHack and is needed because SQLite does not support inserting a completely empty row into a table—this ...

Get Android™ How to Program, Second 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.