Using in-memory sqlite android Using in-memory sqlite android sqlite sqlite

Using in-memory sqlite android


SQLiteOpenHelper() will create an in-memory database if the name is null. Note that it will be created when you invoke getWritableDatabase().

Then you should insert your data.


You (or the framework) create a database using ONE of the following:

  • SQLiteDatabase.create()
  • SQLiteDatabase.openDatabase()
  • SQLiteDatabase.openOrCreateDatabase()

The first option is the only way to create a memory-only database, the other two open or create a database file.

Consequently, if you are using SQLiteOpenHelper() and you pass name as null, the framework calls SQLiteDatabase.create(null), so you will get a database that only lives in memory (it dies when close() is called). There is no need to also call one of the other direct methods. Instead call getReadableDatabase() or getWritableDatabase() from your helper.


You have to be carefull wile using inmemory as your data will be lost once the db connection is lost. Make sure your db instance is not been closed

https://www.sqlite.org/inmemorydb.html