user2011302
user2011302

Reputation: 391

Notifying changes in datatable in android

In my android application, there is a service which inserts records into database table A, and I need to do some operation whenever any new record is inserted in the database table A.

How can I continuously observe table A with a ContentObserver? What URI should I give to get notified whenever any change occurs in table A as we do in order to observe CallLogs and Contacts URIs?

Upvotes: 0

Views: 316

Answers (2)

fdreger
fdreger

Reputation: 12505

You can't "observe a table" with a content provider. Changes in SQLite db cannot trigger any java code.

You can however (and this is what contacts and log providers do) notify everyone interested after each insert.

So:

  • either move your inserting into a custom content provider, and let it notify its listeners,
  • Or - if you need something lighter - send a simple broadcast intent saying "the data has changed" (and listen to the broadcast).

Upvotes: 2

pskink
pskink

Reputation: 24730

the same way: create a custom ContentProvider to access your db tables

Upvotes: 0

Related Questions