For each type of manifest file, you need a receiver definition, for example:
<receiver android:name=".MyWidget" android:label="@string/medium_widget_name"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/medium_widget_provider" /> </receiver> <receiver android:name=".MyWidget" android:label="@string/large_widget_name"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/large_widget_provider" /> </receiver>
This will allow you to use the same AppWidgetProvider class for multiple widgets with different widget names and different sizes defined in the <appwidget-provider> XML.
Now, if you need more differences in your widgets than in XML <appwidget-provider> , I would create a base class of widgets that implements all the usual behavior of different types:
public abstract class MyBaseWidget extends AppWidgetProvider
And then each of your specific implementations can extend MyBaseWidget. Then, in your manifest file, you will have a receiver definition for each of your specific implementations, for example:
<receiver android:name=".MyMediumWidget" android:label="@string/medium_widget_name"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/medium_widget_provider" /> </receiver> <receiver android:name=".MyLargeWidget" android:label="@string/large_widget_name"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/large_widget_provider" /> </receiver>
Mark B Apr 03 '10 at 2:42
source share