Skip to content

Instantly share code, notes, and snippets.

@varundwarkani
Created May 8, 2020 18:16
Show Gist options
  • Save varundwarkani/d8e1ebf6eb4ad2c5c69bc50ea9c97938 to your computer and use it in GitHub Desktop.
Save varundwarkani/d8e1ebf6eb4ad2c5c69bc50ea9c97938 to your computer and use it in GitHub Desktop.
private void restoreDatabase(InputStream inputStreamNewDB) {
appDatabase.close();
//Delete the existing restoreFile and create a new one.
sharedPreferences.edit().putBoolean("restoringDatabase", true).apply();
deleteRestoreBackupFile(getApplicationContext());
backupDatabaseForRestore(this, getApplicationContext());
File oldDB = this.getDatabasePath(DATABASE_NAME);
if (inputStreamNewDB != null) {
try {
Utils.copyFile((FileInputStream) inputStreamNewDB, new FileOutputStream(oldDB));
Utils.showSnackbar(findViewById(android.R.id.content), getString(R.string.restore_success), 1);
//Take the user to home screen and there we will validate if the database file was actually restored correctly.
} catch (IOException e) {
Log.d(LOGGER, "ex for is of restore: " + e);
e.printStackTrace();
}
} else {
Log.d(LOGGER, "Restore - file does not exists");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment