Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

AppWidgetProvider

extends BroadcastReceiver
java.lang.Object
   ↳ android.content.BroadcastReceiver
     ↳ android.appwidget.AppWidgetProvider

Class Overview

A convenience class to aid in implementing an AppWidget provider. Everything you can do with AppWidgetProvider, you can do with a regular BroadcastReceiver . AppWidgetProvider merely parses the relevant fields out of the Intent that is received in onReceive(Context,Intent) , and calls hook methods with the received extras.

Extend this class and override one or more of the onUpdate(Context, AppWidgetManager, int[]) , onDeleted(Context, int[]) , onEnabled(Context) or onDisabled(Context) methods to implement your own AppWidget functionality.

Developer Guides

For more information about how to write an app widget provider, read the App Widgets developer guide.

Summary

Public Constructors
AppWidgetProvider ()
Constructor to initialize AppWidgetProvider.
Public Methods
void onAppWidgetOptionsChanged ( Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)
Called in response to the ACTION_APPWIDGET_OPTIONS_CHANGED broadcast when this widget has been layed out at a new size.
void onDeleted ( Context context, int[] appWidgetIds)
Called in response to the ACTION_APPWIDGET_DELETED broadcast when one or more AppWidget instances have been deleted. Override this method to implement your own AppWidget functionality.
void onDisabled ( Context context)
Called in response to the ACTION_APPWIDGET_DISABLED broadcast, which is sent when the last AppWidget instance for this provider is deleted. Override this method to implement your own AppWidget functionality.
void onEnabled ( Context context)
Called in response to the ACTION_APPWIDGET_ENABLED broadcast when the a AppWidget for this provider is instantiated. Override this method to implement your own AppWidget functionality.
void onReceive ( Context context, Intent intent)
Implements onReceive(Context, Intent) to dispatch calls to the various other methods on AppWidgetProvider.
void onUpdate ( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
Called in response to the ACTION_APPWIDGET_UPDATE broadcast when this AppWidget provider is being asked to provide RemoteViews for a set of AppWidgets. Override this method to implement your own AppWidget functionality.
[Expand]
Inherited Methods
From class android.content.BroadcastReceiver
From class java.lang.Object

Public Constructors

public AppWidgetProvider ()

Added in API level 3

Constructor to initialize AppWidgetProvider.

Public Methods

public void onAppWidgetOptionsChanged ( Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)

Called in response to the ACTION_APPWIDGET_OPTIONS_CHANGED broadcast when this widget has been layed out at a new size.

Parameters
context The Context in which this receiver is running.
appWidgetManager A AppWidgetManager object you can call updateAppWidget(ComponentName, RemoteViews) on.
appWidgetId The appWidgetId of the widget who's size changed.
newOptions The appWidgetId of the widget who's size changed.

public void onDeleted ( Context context, int[] appWidgetIds)

Added in API level 3

Called in response to the ACTION_APPWIDGET_DELETED broadcast when one or more AppWidget instances have been deleted. Override this method to implement your own AppWidget functionality.

Parameters
context The Context in which this receiver is running.
appWidgetIds The appWidgetIds that have been deleted from their host.

public void onDisabled ( Context context)

Added in API level 3

Called in response to the ACTION_APPWIDGET_DISABLED broadcast, which is sent when the last AppWidget instance for this provider is deleted. Override this method to implement your own AppWidget functionality.

Parameters
context The Context in which this receiver is running.

public void onEnabled ( Context context)

Added in API level 3

Called in response to the ACTION_APPWIDGET_ENABLED broadcast when the a AppWidget for this provider is instantiated. Override this method to implement your own AppWidget functionality.

When the last AppWidget for this provider is deleted, ACTION_APPWIDGET_DISABLED is sent by the AppWidget manager, and onDisabled(Context) is called. If after that, an AppWidget for this provider is created again, onEnabled() will be called again.

Parameters
context The Context in which this receiver is running.

public void onReceive ( Context context, Intent intent)

Added in API level 3

Implements onReceive(Context, Intent) to dispatch calls to the various other methods on AppWidgetProvider.

Parameters
context The Context in which the receiver is running.
intent The Intent being received.

public void onUpdate ( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)

Added in API level 3

Called in response to the ACTION_APPWIDGET_UPDATE broadcast when this AppWidget provider is being asked to provide RemoteViews for a set of AppWidgets. Override this method to implement your own AppWidget functionality.

Parameters
context The Context in which this receiver is running.
appWidgetManager A AppWidgetManager object you can call updateAppWidget(ComponentName, RemoteViews) on.
appWidgetIds The appWidgetIds for which an update is needed. Note that this may be all of the AppWidget instances for this provider, or just a subset of them.