AppWidgetProvider:不叫onEnabled方法 [英] AppWidgetProvider: not called onEnabled method

查看:449
本文介绍了AppWidgetProvider:不叫onEnabled方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从内容提供商小部件显示数据。我想知道当内容提供商的变化数据。据我知道的方式来做到这一点是

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

但是,当我添加小部件的第一个实例AppWidgetProvider.onEnabled方法不被调用。 这就是为什么我不能让 registerContentObserver 。 在同onDisabled。

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.

如何解决这个问题呢?

感谢

推荐答案

您需要添加android.appwidget.action.APPWIDGET_ENABLED作为另一个动作:

You need to add android.appwidget.action.APPWIDGET_ENABLED as another action:

<intent-filter>
    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
    <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
    <action android:name="android.appwidget.action.APPWIDGET_DISABLED" />  
</intent-filter>

如果没有,您将不会收到触发onEnabled(),广播

Without that, you will not receive the broadcast that triggers onEnabled().

请注意:APPWIDGET_DELETED为onDeleted(...)       APPWIDGET_DISABLED的onDisabled(...)

note: APPWIDGET_DELETED for onDeleted(...), APPWIDGET_DISABLED for onDisabled(...)

这篇关于AppWidgetProvider:不叫onEnabled方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆