What does the SQLiteOpenHelper class do with a context parameter?

I am extending the SQLiteOpenHelper class. My constructor

 public MyDatabaseHelper(Context context) { super( context, // ??? "MyDatabase.db", // Database name null, // Cursor factory 1 // database version ); } 

What does the SQLiteOpenHelper constructor do with contextual information?

For my application, the constructor will behave the same regardless of the state of the program (context). Can I pass null to context with any future issues?

+7
source share
1 answer

If you specify a null value, it will create a database in memory instead, but you will need to specify a null value for the database name parameter so that it is processed correctly.

This is described in the constructor documentation for context.

context

used to open or create the name of the database database file or null for the database in memory

Also, if you look at the source code of the SQLiteHelper class itself, you will see that it uses the mName value to decide whether to use mContext. Check out the source code here:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/android/database/sqlite/SQLiteOpenHelper.java#SQLiteOpenHelper.0mContext

+6
source

All Articles