Created
May 8, 2020 18:16
-
-
Save varundwarkani/d8e1ebf6eb4ad2c5c69bc50ea9c97938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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