A
A
Andres Iniesta2018-08-05 17:16:09
Java
Andres Iniesta, 2018-08-05 17:16:09

Why is the database not updated when updating an application from the Play Market?

Hi all!
When updating an application from the Play Market, the layout itself is updated, but the database is not updated.
Used the OnUpgrade method, but does not help ((
Here is my code:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// IF THERE IS NEW DB VERSION ON ASSETS FOLDER, REPLACE THE OLD ONE WITH NEW ONE.
if (newVersion > oldVersion) {
InputStream inputStream = null;
OutputStream outputStream = null;
String dbFilePath = DBLOCATION + DBNAME;
Log.d("MYLOG", dbFilePath);
try {
inputStream = mContext.getAssets().open(DBNAME);
outputStream = new FileOutputStream(dbFilePath);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer,0,length);
}
outputStream.flush();
outputStream.close();
inputStream.close();
} catch (IOException e) {
throw new Error("Database replacement error!");
}
}
}
I also changed the database version number from 1 to 2 in the class constructor.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2018-08-05
@zagayevskiy

I don't understand why you do it in such a weird way. This method is for updating the database structure, not for copying files.

A
Andres Iniesta, 2018-08-06
@nuroraf

Denis Zagaevsky
And how it is possible to replace old in a DB at updating? The structure of the database remains the same for me, only data is added to the tables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question