Hi,
In our app there is a predefined db, so after the first opening users download it, unzip it and keep using the app without problem, however sometimes the db may need to be swapped with the new one. Again users download the new db, unzip it but as expected the app does not aware of the latest downloaded until the app gets restarted because it keeps running through the memory.
In order to run by the latest db without restarting the app, we delete the exist db before unzipping the latest db like below
priceDatabase = null;
manager.getDatabase(fileUtil.getPriceDatabaseName()).delete();
sometimes it fires exception saying “SQLiteDatabaseCorruptException: database disk image is malformed (code 11)” and everything gets corrupted suddenly.
So here is my question, how do I swap an exist db with the new one not requiring to restart the app? Deleting seems resolve the restarting problem however the db gets broken after deletion and can not unzip the new one properly.
UPDATE 1: I tried to use replaceDatabase method, it seems copy the source folder as destination but nothing changes.
UPDATE 2: reopening the db having finished unzipping seems solve
@Override public Observable<Boolean> unzip(DatabaseType databaseType) {
return Observable.create((Observable.OnSubscribe<Boolean>) subscriber -> {
try {
fileUtil.unzip(fileUtil.getDownloadedZIPDatabaseFile(databaseType).getPath(),
manager.getContext().getFilesDir());
priceDatabase = null;
manager.getDatabase(fileUtil.getPriceDatabaseName()).close();
manager.getDatabase(fileUtil.getPriceDatabaseName()).open();
Timber.d("%s unzipping is finished successfully", fileUtil.getProductDatabaseName());
createPublicReplications();
subscriber.onNext(true);
subscriber.onCompleted();
} catch (Exception e) {
subscriber.onError(e);
}
}).subscribeOn(worker).observeOn(main);
}