Questions tagged [contentobserver]

Receives call backs for changes to content. Must be implemented by objects which are added to a ContentObservable.

Receives call backs for changes to content. Must be implemented by objects which are added to a ContentObservable.

It has the following public meathods

Public Methods

boolean deliverSelfNotifications()

Returns true if this observer is interested receiving self-change notifications.

final void dispatchChange(boolean selfChange, Uri uri)

Dispatches a change notification to the observer.

final void dispatchChange(boolean selfChange)

This method was deprecated in API level 16. Use dispatchChange(boolean, Uri) instead.

void onChange(boolean selfChange, Uri uri)

This method is called when a content change occurs.

void onChange(boolean selfChange)

This method is called when a content change occurs.

262 questions
31
votes
4 answers

How do I make my Android ContentObserver for ContactsContract detect a added, updated or deleted contact?

I am able to get a generic notification "that there was a change to the contacts DB", but I want to know the specific record that was inserted, updated, or deleted. Following is the code that gets registered and gets the onChange notification. …
mobibob
  • 8,030
  • 17
  • 76
  • 126
31
votes
4 answers

Difference between ContentObserver and DatasetObserver?

What is difference between ContentObserver and DatasetObserver? When one or another should be used? I get Cursor with single row. I want to be notified about data changes - eg. when row is updated. Which observer class should I register?
pixel
  • 21,352
  • 30
  • 113
  • 196
18
votes
3 answers

How to listen contact inserted/updated/deleted in address book

There are lots of questions related to it but none of them help me to get the solution. I am trying to sync all contacts from device to remote server and able to do it easily but when there is a change in contact like update/delete/insert(new…
moDev
  • 5,163
  • 4
  • 31
  • 63
16
votes
2 answers

When ContentResolver.notifyChange() is called for a given URI, are ContentObservers observing descendent URIs of this URI notified?

A hopefully straightforward question: When ContentResolver.notifyChange() is called for a given URI, are ContentObservers observing descendent URIs of this URI notified? E.g. Say I have a cursor setup to observer the URI of a specific resource: Uri…
13
votes
3 answers

Why is the ContentObserver called multiple times?

I have following ContentObserver implementation for receiving and writing SMS, but it is called multiple times. Code: public class SMSObserverActivity extends Activity { protected MyContentObserver observer = null; /** Called when the…
CSchulz
  • 10,102
  • 9
  • 54
  • 107
13
votes
2 answers

Observing changes in Android content observer for Audio.Media.EXTERNAL_CONTENT_URI

I am developing an Android app in which I have to detect changes in Android SD card for audio files with the file name, file path and operation performed upon it. Example if I am adding a file in my SD card then I want to know Name of the file…
12
votes
2 answers

Can you determine what contact changes w/ registerContentObserver?

Just trying to determine if there is an easy way to determine what contact changes when using registerContentObserver, or some other method? I can tell when the database changes, but not sure I want to check all the records each time an…
Chrispix
  • 16,821
  • 19
  • 60
  • 68
12
votes
3 answers

Android notify when phone book is updated(Content Observer)

I want to get a notification on my phone if there is any change in the contact database(add,delete).Right now i am using ContentObserver to get notified.Following is my code.Problem is that i able not able to know which contact is changed.Can anyone…
Karan_Rana
  • 2,789
  • 2
  • 23
  • 34
11
votes
1 answer

How to use ContentObserver with RecyclerView?

With ListView we have had a good native pattern to map some data from db to list: DB -> ContentProvider -> CursorLoader -> CursorAdapter -> ListView This approach was good in terms of data layer separation, performance and automatic data updates.…
11
votes
2 answers

ContentObserver should call if and only if ContactsContract.Contacts.CONTENT_URI changes

As my application uses content from android.provider.ContactsContract.Data (API > 11) and ContactsContract.Contacts.CONTENT_URI (API < 11) to populate Contacts. I've tried to registerContentObserver() against these provider. But it calls my…
Vikalp Patel
  • 10,082
  • 6
  • 55
  • 92
10
votes
4 answers

Android: content observer's "onChange()" method is called multiple times

I am using a content observer for content://sms. I am writing all the messages to a text file in SD card. But the onChange() method in the content observer is called multiple times and the same message is written multiple times to the text file. How…
Vivek
  • 4,204
  • 15
  • 54
  • 65
10
votes
1 answer

Content Observer's onChange Method fired multiple Times

I know you are tempted to mark this a duplicate but wait, let's go through this again with my detailed (but failed) attempts. Strategy 1: Algorithm: Answer The first time the onChange is fired, get the id of the row updated The next time the…
10
votes
3 answers

ContentObserver onChange

The documentation of the ContentObserver is not clear to me. On which thread is the onChange of a ContentObserver called? I checked and it is not the thread where you created the observer. It looks like it is the thread that sends the notification…
user1175790
9
votes
1 answer

ContentObserver for listening contact changes

I really don't understand why content observer listens the changes which is not related with the contact info. I simply registered to the URI which I wanna listen the…
Coldfish
  • 348
  • 2
  • 16
8
votes
1 answer

FIleObserver and ContentObserver not working in Android Marshmallow

I have issue with both FIleObserver and ContentObserver not working in Android Marshmallow. I am using this thing for detecting changes that happening inside a folder. I set run time permissions for marshmallow. But after that also it shows no…
1
2 3
17 18