I'm using SQLiteAssetHelper for importing ready databases into my app.
Now I want to release a 2nd version of my database, but when users update the app, the database in not updating. I see documentation and saw I must use setForcedUpgrade(), but i don't know where to use it, I'll appreciate if you guide me. :)
MyDatabase.java :
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "database.db";
private static final int DATABASE_VERSION = 2;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}}
And I read database with these:
MyDatabase my;
SQLiteDatabase sq;
my = new MyDatabase(getApplicationContext());
sq = my.getWritableDatabase();
Thanks by the way.
For your example:
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "database.db";
private static final int DATABASE_VERSION = 2;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
//FORCE UPGRADE BY DELETING OLD DATABASE
setForcedUpgrade(DATABASE_VERSION);
}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With