Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite DB notifications

I am writing an Android app that needs to be notified whenever a given SQLite database changes (any new row added, deleted or updated).

Is there any programmatic way to listen to these notifications ?

Is writing DB triggers for each table the only way ?

like image 683
Sriram Avatar asked Jan 09 '12 04:01

Sriram


2 Answers

SQLite provides Data Change Notification Callbacks. I don't think that Android exposes them directly but it does have for example CursorAdapter which provides some change notifications.

As thinksteep asked however, do you expect your DB to be changed outside the scope of your own application?

like image 131
NuSkooler Avatar answered Nov 19 '22 10:11

NuSkooler


You can register an observer class such as DataSetObserver

Then whenever you change something you can call cursor.registerDataSetObserver(..) to register observe changes.

It's not well documented but I'm sure that there are some examples out there

like image 20
Moog Avatar answered Nov 19 '22 11:11

Moog