I came across this question since i was also have the same question, but I have an idea but have never tried it yet but you can maybe execute it faster and better than me. I think eventbus(https://github.com/greenrobot/EventBus) can be a solution, whenever there is a change in the local database (add,delete,update) you can notify an event, and in your activity you should have an event listener that will trigger content reload(re-query again) upon receiving the event.
Android: How to use greenDao for async loading data?
Question
I would like use greenDao with a loader <cursor> to load asynchronously my data from the DB. I found example using loader with a contentProvider. I know that loaders are the best way to load data from a database because it handle the lifecycle of the cursor, auto update the cursor when we add a value.. Unfortunately there is no example of loader with greenDao, is it possible or I have to use a contentProvider??
Thx
No correct solution
OTHER TIPS
GreenDao allows you to run queries and return strongly typed objects, so a loader isn't needed, you can simply wrap it in an ASyncTask. e.g.:
DaoSession session = DbHelper.getInstance().getDaoSession();
final SpeakerDao speaker = session.getSpeakerDao();
new AsyncTask<Void, Void, Speaker>() {
@Override
protected Speaker doInBackground(Void... params) {
return speaker.queryBuilder().list().get(0);
}
@Override
protected void onPostExecute(Speaker result) {
// do stuff with speaker
}
}.execute();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow