AppWidgetProvider:未调用 onEnabled 方法
我有显示来自内容提供商的数据的小部件。我想知道内容提供商中的数据何时发生变化。据我所知,方法是
context.getContentResolver().registerContentObserver
但当我添加小部件的第一个实例时,不会调用 AppWidgetProvider.onEnabled 方法。 这就是为什么我无法进行registerContentObserver
。 与 onDisabled 相同。
如何解决这个问题呢?
谢谢
I have widget that display data from content provider. I want to know when data in content provider changes. As far as I know way to do it is
context.getContentResolver().registerContentObserver
But AppWidgetProvider.onEnabled method is not called when I add first instance of the widget.
That's why I can't make registerContentObserver
.
The same with onDisabled.
How to solve this problem?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要添加 android.appwidget.action.APPWIDGET_ENABLED 作为另一个操作:
没有它,您将不会收到触发 onEnabled() 的广播。
注意:APPWIDGET_DELETED 用于 onDeleted(...),
APPWIDGET_DISABLED 用于 onDisabled(...)
You need to add android.appwidget.action.APPWIDGET_ENABLED as another action:
Without that, you will not receive the broadcast that triggers onEnabled().
note: APPWIDGET_DELETED for onDeleted(...),
APPWIDGET_DISABLED for onDisabled(...)
AppWidgetProvider
(或任何其他清单注册的BroadcastReceiver
)无法调用registerContentObserver()
。正在更改内容的实体将需要更新您的应用小部件,或者您将需要实现某种轮询机制(例如,基于android:updatePeriodMillis
检查新内容)。An
AppWidgetProvider
(or any other manifest-registeredBroadcastReceiver
) cannot callregisterContentObserver()
. The entity that is changing your content will need to update your app widget, or you will need to implement some sort of polling mechanism (e.g., check for new content based onandroid:updatePeriodMillis
).