I am using GreenDao in one of my Android projects. I am trying to implement an observer / listener when the changes are made.
So far I have created the basic functions of static functions (save, replace and delete) that just send an event (via EventBus), but this approach gives me a lot of headaches.
I'm currently trying to use ContentObserver, which for some reason does not work (see the attached code), but I would like you to hear suggestions for other common solutions.
observer:
public class DBObserver extends ContentObserver {
public DBObserver() {
super(null);
Logger.e("DBObserver was initialized!");
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.d("SOMETHING CHANGED IN DB OBSERVER");
}
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
Log.d("SOMETHING CHANGED IN DB OBSERVER");
}
}
for the observer (implemented in the onCreate application):
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, DB_NAME, null);
SQLiteDatabase db = helper.getWritableDatabase();
DaoMaster daoMaster = new DaoMaster(db);
DaoSession daoSession = daoMaster.newSession();
getContentResolver().registerContentObserver(TicketModelContentProvider.CONTENT_URI, true, new DBObserver());
Thanks.