How Can I Refresh/reopen An Sqlite Database After Restoring It, When Using A Singleton For The Database Helper
I have incorporated Database Backup and restore in my App. This all works fine except that when I restore the database, due to the use of a singleton DBHelper along with only closi
Solution 1:
The trick is very simple, do not close the database just reset the DBHelper
.
So the reopen method could be:-
publicstaticvoidreopen(Context context) {
instance = newDBHelper(context);
}
Of course, you could also do away with the text telling the user to close and restart the App.
So the code that detects and reports on a successful restore could be:-
if(copytaken && origdeleted && restoredone) {
errlist.add("Database successfully restored.");
resulttitle = "Restore was successful.";
DBHelper.reopen(context); <== implemented as below
}
Solution 2:
the reopen code that worked for me was:
publicvoidreopen(Context context, String DbFilePath) {
instance = newDBHelper(context, DbFilePath);
}
the difference from the previous answer is the removal of the "static" from the function definition which required the instance to be static as well. this prevented the actual reopening of the database
Post a Comment for "How Can I Refresh/reopen An Sqlite Database After Restoring It, When Using A Singleton For The Database Helper"