Create the Database Helper Class

The recommended approach to using SQLite in an Android app is to create a Database Helper class whose only function is to provide for the creation, modification, and deletion of tables in the database. The new class is defined as a subclass of the SQLiteOpenHelper class. Much of the required functionality for working with databases is inherited from the SQLiteOpenHelper class although some of its methods will be overridden to implement the functionality required for this app.

1. Right-click com.example.mycontactlist in the src folder of the Package Explorer.

2. Select New > Class and enter ContactDBHelper as the name of the new class.

3. Type the code in Listing 5.1 into the new class. You will have to import ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.