Android – Using SQLite DataBase

Android OS comes with SQLite Database already built-in. This article will explain how to store and draw data. Currently I am working with Android version 2.2. 1. Extend SQLiteOpenHelper SQLiteOpenHelper is the main class responsible for SQLite operations. You will need to extend it. After extending SQLiteOpenHelper, you will need to trigger the super constructor with the proper parameters – the context (which Activity inherit from it) , the DB file name, CursorFactory (which we wont discuss in this article, leave it as null for now) and the DB version. 2. Create a table One of the functions you have inherited from SQLiteOpenHelper is public void onCreate(SQLiteDatabase db), which is triggered when the DB was created. You can use this function to create the table. 3. Create SQL queries From this point it is fairly easy to create SQL queries. Your object is now holding reference to 2 objects one for writing/deleting and one for reading. You will use them to make operations. Further reading – Android developer website Download demo project