I've been having a LOT of trouble with Android database since I started my app two months ago... I went through many tutorials, but only few questions were answered... I gave up using my (real) device database, 'cause I couldn't have access to it, so I started using an emulator. But something weird happens. I have this class:
public class DatabaseHandler extends SQLiteOpenHelper
{
@Override
public void onCreate(SQLiteDatabase database)
{
database.execSQL(sql_command);
}
}
Whenever I uninstall the app, the database should be completely deleted from the (virtual) device, correct? But when I reinstall it and put a breakpoint in the execSQL() line (before the method is executed), I can see through SQLite Manager tab that the database is as it was before: The category table has only the _id, name, description, current_level and status.
The current sql command is (Notice the new image column int the Category table):
create table categories(
_id integer primary key autoincrement,
name text not null,
description text not null,
current_level integer DEFAULT 0,
status integer DEFAULT 0,
image text not null);
create table levels(
_id integer primary key autoincrement,
category_id integer not null,
level integer,
total_questions integer,
answered_questions integer DEFAULT 0,
correct_answers integer DEFAULT 0,
time integer DEFAULT 0);
Not only the image column is inserted, but also the level table doesn't show on the database. Besides, when I run the execSQL() method, nothing shows on the logcat tab.
By the way, I'm using Ubuntu 12.10, Eclipse Juno and Android 2.2!
If you actually are uninstalling it, and if the database is in its normal location on internal storage, then yes.
Note that simply running your modified app does not uninstall the old version. It replaces the old version, but all data is kept intact.
To get rid of your existing database on internal storage, you can:
Truly uninstall the app, or
Click on Clear Data for your app in Settings
If you have altered the behavior of
SQLiteOpenHelper
to put the database on external storage, then the database will only be removed on uninstall if it is ingetExternalFilesDir()
,getExternalCacheDir()
, or some subdirectory of those. If you put the database in, say, the root of external storage, then the database will remain intact after an uninstall.In your code shown above, you are not logging anything to LogCat.