Reload SQLiteOpenHelper and re-query
In my app I have a import/export functionality, by importing, the SQLite database file is replaced by one on the sdcard, so I need to reload the SQLiteOpenHelper and then notify all the Queries.
Something like the following method would be really handy!
public void reloadDatabase(SQLiteOpenHelper helper, Set<String> tables){
// Replace the SQLiteOpenHelper
synchronized (databaseLock) {
readableDatabase = null;
writeableDatabase = null;
this.helper.close();
this.helper = helper;
}
// Make all Queries to reload
sendTableTrigger(tables);
}
Or prehaps BriteDatabase can save a Set of tables, filled as we query them, to be notified on a potential database reload?
I guess I could make the user restart the app, but I rather not.
SQLBrite is amazing as it is very simple and allow us to get rid of loaders, and IMO notifying on tables is far better than the Uri system, thanks for creating SQLBrite!
Re-query only
Let's say my app is a calendar, I have an upcoming event list, starting by today's events.
In every event list I want to mark each yesterday's event as missed.
Then I need to reload event's Queries every day at 00:00.
In this particular case it would make sense to make the sendTableTrigger() public and call it every day.
I could also use a Observable.combineLatest with a Query and a PublishSubject and call this Subject every day to run the Query again, but since table triggers are managed the same way, it seems simple to switch sendTableTrigger() to public.
To support this idea; ContentResolver's notifyChange(Uri uri, null) is public.