Content observer is being called even if the Contacts are not changed

3.1k Views Asked by At

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

1

There are 1 best solutions below

2
On

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. :)