Before we dig in to the code for creating an App Widget, let's cover the basics. There are three required and one optional component:
The
AppWidgetProviderInfo
file: It's an XML resource described later onThe
AppWidgetProvider
class: This is a Java classThe View layout file: It's a standard layout XML file, with some restrictions listed later on
The App Widget configuration Activity (optional): This Activity launches when placing the widget to set configuration options
The AppWidgetProvider
must also be declared in the AndroidManifest
file. Since the AppWidgetProvider
is a helper class based on the Broadcast Receiver, it is declared in the manifest with the <receiver>
element. Here is an example manifest entry:
<receiver android:name="AppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" ...