I'm implementing a widget and I'm facing the following problems:
1) onUpdate
is called when I add the widget to the home screen, even if I specified a Configuration Activity. As soon as I add it to the home screen, the APPWIDGET_ENABLED
broadcast is sent, followed by the APPWIDGET_UPDATE
and then the configuration activity is launched.. Is this a bug? How should I understand in the onUpdate
method that is being invoked before the configuration activity has returned? I can do it through a shared preference value, but I'd like it to behave as written on the developer guide, i.e. the onUpdate
method should not be called.
2) onUpdate
is not called every updatePeriodMillis
seconds, which have been set to 10000
, i.e. 10
seconds for testing purposes.. Did I miss something in the receiver
declaration within the Manifest file? I keep receiving the Lint warning Exported receiver does not require permission but I think this is a Lint issue and not my fault.
EDIT: I've just found this within the reference docs: Note: Updates requested with updatePeriodMillis will not be delivered more than once every 30 minutes. So it is correct that the widget is not updated how often I'd specified and I've changed the time to 1800000
milliseconds.
3) I want to deliver my own broadcast action to the widget provider, is it correct to add another receiver
block in the Manifest targeting the same provider class or should I add only another intent action within the intent-filter
that contains the APPWIDGET_UPDATE
action? BTW, I've commented my second receiver
block and it is not the cause of the problems above. I created another receiver
block because I wanted to declare it as not exported, in order to let the intent-filter
action be triggered only by my app code and not anyone else.
AndroidManifest.xml
<receiver android:name="MyWidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/my_widget_info" />
</receiver>
<receiver android:name="MyWidgetProvider"
android:exported="false">
<intent-filter>
<action android:name="org.test.mywidget.FORCE_SMALL_WIDGET_UPDATE" />
</intent-filter>
</receiver>
my_widget_info.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp"
android:minHeight="110dp"
android:updatePeriodMillis="1800000"
android:initialLayout="@layout/my_widget_layout"
android:configure="org.test.mywidget.MyWidgetConfiguration"
android:resizeMode="none">
</appwidget-provider>