【问题标题】:Content observer is being called even if the Contacts are not changed即使没有更改联系人,也会调用内容观察者
【发布时间】:2012-05-29 21:32:11
【问题描述】:

我遇到了一个奇怪的问题,我正在使用ContentObserver 来捕获联系人中的更改,但问题是即使我没有进行任何更改,也会调用onchange() 方法。这是我的代码:

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;
        }
    }

有人可以帮忙吗?
提前致谢

【问题讨论】:

  • 那么它什么时候被调用?
  • 它随时被调用,我没有使用任何被调用的设备,当设备与gmail帐户同步时也会调用它
  • @Josephus Villarey @AnasBakez 将您的 URI 更改为 ContactsContract.Contacts.CONTENT_VCARD_URI 并将 notifyForDescendents 设置为 false
  • ContactsContract.Contacts.CONTENT_VCARD_URI 并将 notifyForDescendents 设置为 false 并不能解决问题。我知道这个问题很老了,但还有其他解决方法吗?

标签: android contentobserver


【解决方案1】:

registerContentObserver 方法接受布尔值 notifyForDescendents 变量,您将其设置为 true。也许将其设置为 false?

否则,某些后台任务可能会干扰您的观察者。 :)

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-11-09
  • 1970-01-01
  • 1970-01-01
  • 2015-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-23
相关资源
最近更新 更多