Android Basics – Learn how to get a reference to the Database

In the last lecture you learnt how to query your database. In order to query or perform any operation on the database you need to get a reference to it.

This can be done using getReadableDatabase() or getWritableDatabase()

Refer to the sample code below, in which these methods are used to get the SurveyDBHelper object in MainActivity class

SurveyDBHelper surveyDBHelper = new SurveyDBHelper(this);
SQLiteDatabase db = surveyDBHelper.getReadableDatabase();

Follow the video to understand this better. You can refer to the source code here.