Marek J.
Marek J.

Reputation: 317

Android AppWidgetProvider not receiving local broadcasts

When I send local broadcast from a service (extending IntentService) it's not received in onReceive in my AppWidgetProvider, but the same broadcast is received if not sent locally. Is it normal?

EDIT: I forgot to mention that in my AndroidManifest I have <action> inside <intent-filter> for AppWidgetProvider <receiver> like this:

<receiver android:name="MyAppWidget">
<intent-filter>
    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    <action android:name="my.package.MY_ACTION" />
</intent-filter>
...

and in MyAppWidget extending AppWidgetProvider in 'onReceive' I have:

if (intent.getAction().equals("my.package.MY_ACTION")) {
    // do something
}

Upvotes: 1

Views: 722

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006734

If by "local broadcast", you mean LocalBroadcastManager, an AppWidgetProvider will not respond to those by default. An AppWidgetProvider is listening to system broadcasts, by means of its <receiver> element.

Moreover, this should not be necessary. There is nothing magic about an AppWidgetProvider — it is merely a designated place for the system to let you know about changes in app widget state. You can update your app widget contents from any portion of your app, by means of AppWidgetManager.

Upvotes: 2

Related Questions