Reputation: 1279
I am extending the SQLiteOpenHelper
class. My constructor is
public MyDatabaseHelper(Context context) {
super(
context, // ???
"MyDatabase.db", // Database name
null, // Cursor factory
1 // database version
);
}
What does the SQLiteOpenHelper constructor do with the context information?
For my application, the constructor will behave the same regardless of the program state (context). Can I pass null in for the context with out any future problems?
Upvotes: 6
Views: 4177
Reputation: 5372
If you supply a null value, it will create an in-memory database instead but you'll need to supply null for the database name parameter as well so it's handled properly.
This is documented in the constructor documentation for context
context to use to open or create the database name of the database file, or null for an in-memory database
Also, if you view the source code of the SQLiteHelper class itself, you will see it uses the mName value to decide whether to use mContext. View the source code online here:
Upvotes: 6