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

回眸只為那壹抹淺笑 提交于 2019-12-12 08:15:01

问题


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:


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



来源:https://stackoverflow.com/questions/10718181/content-observer-is-being-called-even-if-the-contacts-are-not-changed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!