If we look at the source code, we see that in the constructor mName
would get set to null
.
public SQLiteOpenHelper(Context context, String name, CursorFactory factory, int version,
DatabaseErrorHandler errorHandler) {
if (version < 1) throw new IllegalArgumentException("Version must be >= 1, was " + version);
mContext = context;
mName = name;
mFactory = factory;
mNewVersion = version;
mErrorHandler = errorHandler;
}
Which means getDatabaseName()
returns null
.
public String getDatabaseName() {
return mName;
}
Later, through the use of getReadableDatabase()
or getWritableDatabase()
, if mName
is null
, then it calls the create
method for an in-memory database instead of trying to opening one from disk.
if (mName == null) {
db = SQLiteDatabase.create(null); // in-memory
} else {
// db file opened or created
}
...
return db;
That db
variable is maintained in the SQLiteOpenHelper
until it is closed, which in the case of an in-memory database, means the data is deleted.
To clarify,
Each instance of a SQLiteOpenHelper
that uses an in-memory database will its own database while the same instance will use one database and persist that data until it is closed.