5

I would like to listen to any changes in a cursor. Is it possible to achieve this without using a contentprovider in android?

Note:(I am not using any data adapter)

Thanks

General Grievance
  • 4,555
  • 31
  • 31
  • 45
rogerstone
  • 7,541
  • 11
  • 53
  • 62
  • 1
    Take a look at `registerContentObserver()` or `registerDataSetObserver()`. See http://developer.android.com/reference/android/database/Cursor.html – ramdroid Mar 13 '12 at 09:09

2 Answers2

3

I found that You don't need to use content Provider.When ever the data changes(like during insertions,deletions etc..) you can just call getContentResolver().notifyChange(Uri uri, ContentObserver observer) and set a contentObserver in your activity to listen for the change.

rogerstone
  • 7,541
  • 11
  • 53
  • 62
0

As far as I know, if your changes in the cursor are due to requery() or some other method on the cursor like close(), then you can use a dataset observer to track the changes.

But you will need a content provider, if you want to be updated automatically when something changes in your data source, eg your sqlite database.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Shubhayu
  • 13,402
  • 5
  • 33
  • 30