4

I am facing a problem that is strange, i am using the ContentObserverto catch the changes in the contacts, but the problem is that the onchange() method is called even if i am not making any changes. Here is my code :

getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, new MyCOntentObserver());

public class MyCOntentObserver extends ContentObserver{
        public MyCOntentObserver() {
            super(null);
        }
        @Override
        public void onChange(boolean selfChange) {
        super.onChange(selfChange);
            Log.e("","~~~~~~"+selfChange);
        }  

        @Override
        public boolean deliverSelfNotifications() {
            Log.e("","~~~~~~ Change");
            return true;
        }
    }

any one can help?
thanks in advance

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
AnasBakez
  • 1,230
  • 4
  • 20
  • 36
  • when is it being called then? – josephus May 23 '12 at 10:49
  • it is being called at any time, iam not using the device any it is being called, it is also called when the device syncs with the gmail account – AnasBakez May 23 '12 at 11:33
  • 1
    @Josephus Villarey @AnasBakez change your `URI` to **ContactsContract.Contacts.CONTENT_VCARD_URI** and set `notifyForDescendents` to **false** – Ahmad Kayyali May 23 '12 at 12:10
  • ContactsContract.Contacts.CONTENT_VCARD_URI and setting notifyForDescendents to false, doesn't resolve the issue. I know the question is old, but is there any other work around? – Abir Hasan Shawon Sep 20 '16 at 13:11

1 Answers1

0

The registerContentObserver method accepts a boolean notifyForDescendents variable, which you're setting to true. Maybe set that to false?

Otherwise maybe some background task is messing with your observer. :)

josephus
  • 8,284
  • 1
  • 37
  • 57
  • Check notifyForDescendents Documentation http://developer.android.com/reference/android/content/ContentResolver.html#registerContentObserver(android.net.Uri, boolean, android.database.ContentObserver) – Ahmad Kayyali May 23 '12 at 11:47
  • How can i Know what is calling the OnChange method? – AnasBakez May 24 '12 at 07:38