我有一个内容观察者,当我的同步适配器添加的联系人之一被修改时应该被通知。 我注册和注销观察者这样做:即使光标没有变化,也会调用ContentObserver
private static final Uri MYAPP_CONTENT_URI = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, SyncAdapter.MYAPP_ACCOUNT_NAME).appendQueryParameter(RawContacts.ACCOUNT_TYPE, MY_APP_ACCOUNT_TYPE).build();
public static void registerContentObserver() {
ContentResolver resolver = MyApplication.getAppContext().getContentResolver();
cursorContacts = resolver.query(MYAPP_CONTENT_URI, null, RawContacts.DELETED + "=0", null, null);
cursorContacts.registerContentObserver(MYAPP_URI_OBSERVER);
}
public static void unregisterContentObserver() {
if (cursorContacts != null) {
cursorContacts.unregisterContentObserver(MYAPP_URI_OBSERVER);
cursorContacts.close();
}
}
的问题是,即使当光标是空的(getCount将返回0)后,我注册的观察者,我得到一个调用的OnChange什么都我在本地做地址簿。 仅当光标中的一个条目被修改时,才会调用观察者吗? 文档状态:
注册时的变化发生在内容后盾此光标
什么是“正在备份此光标的内容”,也就是所谓的观察者?我认为它是光标中联系人的lookupuri列表,但它看起来像在ContactsContract.RawContacts.CONTENT_URI中有足够的改变。
我也试着为每个Uri注册一名观察员。它没有帮助。虽然ContentResolver.registerContentObserver文档指出:
注册一个观察者类,获取回调时由给定的内容URI标识的变化数据。
Parameters
uri The URI to watch for changes. This can be a specific row URI, or a base URI for a whole class of content.
notifyForDescendents If true changes to URIs beginning with uri will also cause notifications to be sent. If false only changes to the exact URI specified by uri will cause notifications to be sent. If true, than any URI values at or below the specified URI will also trigger a match.
(我设置notifyForDescendents为false,但它不应该有所谓的在任何情况下观察者)。
怎么了? 谢谢
那么为什么文档会说一些不同的东西? – kingston 2012-02-28 16:40:58