The problem is, if i make changes in sqlite database, i need to update
the version and then all listview items are gone because database has
been updated but recorded files are stored in app data directory.
(after editing the question)
The problem I have is that if I make structural changes to the SQlite
database (e.g. to add a new column), I need to update the version,
which then results in onUpgrade deleting the tables and thus all of
the data. Therefore there are no ListView items.
You don't actually have to update the version (you can utilise your own methodology if you wish). However, even if you do then you can utilise code to retain the old data. That is you are not necessarily limited to using the much seen, much copied, DROP TABLE call onCreate model e.g.:-
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
You can use ALTER TABLE to add a column e.g
ALTER TABLE log ADD COLUMN extra TEXT DEFAULT extra ;
Using the the above resulted in:-
Where column extra was added, noting that the default value was applied and that existing data was retained (PS increasing version/onUpgrade
wasn't used).
Here's an article that briefly discusses the DROP TABLE call onCreate model, which includes other pointers Android SQLite Database, WHY drop table and recreate on upgrade.