I am working on an Android application. As I upgrade the application, the database is re-created ie the onCreate()
method of SQLiteOpenHelper
class executes again.
I have read that the app upgrade should not touch the database unless you increment the database version.
The database version remains same in the two versions, however, the application version changes.
Could anyone suggest me why my application is recreating the database upon app upgrade ?
Update 1:
My OnCreate() looks like this :
public override void OnCreate(SQLiteDatabase db)
{
db.ExecSQL(DataContract.ENGINE_TYPE.CREATE_TABLE);
db.ExecSQL(DataContract.ENGINE_GPS.CREATE_TABLE);
}
And I don't have anything in OnUpgrade() method.
And then I have code in the contract file that creates the table. The database is created perfectly and I can fetch the data using queries, but after the app upgrade (not database) all the existing data is lost. However, since I run the debug mode, so I can see OnCreate() method executing again.
Update 2:
DataContract class looks like this :
class DataContract{
public class ENGINE_TYPE
{
public static string TABLE = "TypeInfo";
public static string COLUMN_ENGINE_ID = "engine_id";
public static string COLUMN_ENGINE_DESC = "engine_desc";
public static string CREATE_TABLE = "CREATE TABLE " + TABLE +
"(" + COLUMN_ENGINE_ID + " TEXT PRIMARY KEY " + " NOT NULL , " +
COLUMN_ENGINE_DESC + " TEXT NOT NULL);";
}
}
The other tables are also similar to this one.
Update 3:
My App Upgrade means only increasing the app version not database version.
I have deployed the application by creating APKs for the two versions. So, the upgrade is installing the latest version apk when a previous version apk already exists.
Next, I have also tried installing APK directly in deploy mode. Here also installing the latest version on top of an already installed app. So, I can see the program flow going through onCreate() method of SQLiteOpenHelper class in debug mode.
And I am working on Xamarin on Visual Studio