Android Database Tutorial
This tutorial will cover the basics of using the SQLite database tools in Android. I am going to try to organize this tutorial so that it is easy to navigate, for myself and others, to use as a reference. At the same time, I will try to make it long enough so that people needing the extra help will be able to read through the entire tutorial to gain understanding on how to use databases in Android. Finally, I did some pretty heavy commenting in the code. You can jump straight to that if you prefer to read through just the code and comments. Let’s get started.
The Android SDK provides two basic tools that assist you in writing basic programs that access a database in the Android environment. The first tool is SQLiteOpenHelper – which is responsible for creating, opening, and upgrading a program’s database. The other tool is SQLiteDatabase – which is responsible for communicating changes to the data within the database. Once you know how to use these two classes, you should be able to write programs that create and communicate with an Android database.
In this tuturial, I will first go about creating a database manager class that can be modified and plugged into most apps. This program will make use of both the SQLiteOpenHelper and the SQLiteDatabase classes. Afterwords, we will create a simple application that will instantiate and use our new database manager class.
Table of Contents
- Getting Started
- Setting Up the SQLiteOpenHelper for Use
- Creating the Database Manager Class
- CODE: The AABDatabaseManager.java Class
- The Example Application Explained
- CODE: The Application XML
- The Main Activity
- CODE: The DatabaseExampleActivity.java Class
- Wrap Up