Is there a memory cache for SQLite in Android and how do I release or clear it?

First, I create a database called "mydb" in my Android application:

DBHelper dbHelper = new DBHelper(context, "mydb", null, 1);//DBHelper is my custom class

And write some data in the table:

SQLiteDatabase db = dbHelper.getReadableDatabase();
db.execSQL("insert into mytable(name, text) values ('allen','hello')");

Everything is in order here. But then I delete this database manually, without programming, with the software "RE expl" (Of course, on the root device).

Then in my code I read this database table. What is surprising is that I can still get the saved data.

Cursor cursor = db.query("mytable", new String[]{"name","text"}, null, null, null, null, null);

Why?

+4
source share
3 answers

Quote from the Android Developers website:

, , . ( close(), .)

getWritableDatabase(), getReadableDatabase() getWritableDatabase() .

, getWritableDatabase(), . . , SQLiteDatabase close(), .

+3

,

0

use the SQLiteDatabase.deleteDatabase(File file)API to delete the database

Deletes the database, including the log file and other supporting files that can be created by the database engine.

Make sure you close all open connections.

If you cannot do this, just run deleteDatabase followed by the kill .. process - not recommended

0
source

All Articles