Search code examples
androidandroid-sqlitesqliteopenhelper

SQLiteOpenHelper multiple in-memory databases


android.database.sqlite.SQLiteOpenHelper provides the ability to use an in-memory database if the name argument to its constructor is null:

String: of the database file, or null for an in-memory database

If SQLiteOpenHelper is instantiated multiple times with a null name argument, do they access the same in-memory database or is a separate in-memory database created each time?


Solution

  • From SQLite official documentation In-Memory Databases

    Opening two database connections each with the filename ":memory:" will create two independent in-memory databases.

    In Android, pass null instead of ":memory:"

    So, If you instantiate SQLiteOpenHelper multiple times with a null name argument then it create separate in-memory database created each time