gpt4 book ai didi

android - 当为给定的 URI 调用 ContentResolver.notifyChange() 时,是否会通知观察该 URI 的后代 URI 的 ContentObservers?

转载 作者:IT老高 更新时间:2023-10-28 23:28:50 25 4
gpt4 key购买 nike

一个有希望的直截了当的问题:当 ContentResolver.notifyChange() 为给定的 URI 调用时,ContentObserver 是否在观察 descendent URI URI 通知?

例如假设我有一个光标设置来观察特定资源的 URI:

 Uri uriA = Uri.parse("content://" + AUTHORITY + "/orders/21");
cursor.setNotificationUri(getContext().getContentResolver(), uriA);

然后我通知 ContentResolver 该 URI 的祖先发生更改(例如,因为我已删除所有订单):

 Uri uriB = Uri.parse("content://" + AUTHORITY + "/orders");
getContext().getContentResolver().notifyChange(uriB, null);

我的 Cursor 注册观察 uriA 会收到通知吗?

最佳答案

这取决于它是如何注册的。如果 ContentObserver 注册时将 notifyForDescendents 参数设置为 true,则可以。否则不行。

注册是通过方法完成的 ContentResolver#registerContentObserver :

void registerContentObserver (Uri uri, boolean notifyForDescendents, ContentObserver observer)

关于android - 当为给定的 URI 调用 ContentResolver.notifyChange() 时,是否会通知观察该 URI 的后代 URI 的 ContentObservers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6678046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com