AppWidgetProvider: not called onEnabled method

天涯浪子 提交于 2019-12-01 12:38:10

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>

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

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

An AppWidgetProvider (or any other manifest-registered BroadcastReceiver) cannot call registerContentObserver(). 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 on android:updatePeriodMillis).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!