An App Widget is a miniature application view that can be embedded into other applications (such as the Home screen) and receive periodic updates. Common examples include weather widgets and music player controls.

Architecture
An App Widget consists of three core components:
- AppWidgetProviderInfo: metadata defining the widget (layout, update frequency, size), declared in XML
- AppWidgetProvider: extends BroadcastReceiver, handles widget lifecycle events
- View Layout: the widget’s UI layout, built using RemoteViews
Key Lifecycle Methods
| Method | Trigger |
|---|---|
onUpdate() | At each update interval; the only required method |
onAppWidgetOptionsChanged() | When the widget is resized |
onEnabled(Context) | When the first widget instance is created |
onDisabled(Context) | When the last widget instance is removed |
onDeleted(Context, int[]) | When widget instances are deleted |
How to Create a Widget
1. Define Widget Metadata
res/xml/example_appwidget_info.xml:
| |
2. Create the Layout
Widget layouts use RemoteViews, which supports a limited set of views (FrameLayout, LinearLayout, RelativeLayout, GridLayout, Button, TextView, ImageView, etc.):
res/layout/example_appwidget.xml:
| |
3. Implement the Provider
| |
4. Declare in AndroidManifest
| |
Limitations
- Custom Views or View subclasses cannot be used — only views supported by RemoteViews
- Update frequency is managed by the system;
updatePeriodMillishas a minimum of 30 minutes - ListView and GridView widgets require a RemoteViewsService for data provision