Skip to content

Most visited

Recently visited

navigation

AppWidgetProvider

public class AppWidgetProvider
extends BroadcastReceiver

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


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 onRestored(Context context, int[] oldWidgetIds, int[] newWidgetIds)

Called in response to the ACTION_APPWIDGET_RESTORED broadcast when instances of this AppWidget provider have been restored from backup. If your provider maintains any persistent data about its widget instances, override this method to remap the old AppWidgetIds to the new values and update any other app state that may be relevant.

This callback will be followed immediately by a call to onUpdate(Context, AppWidgetManager, int[]) so your provider can immediately generate new RemoteViews suitable for its newly-restored set of instances.

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

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

Inherited methods

From class android.content.BroadcastReceiver
From class java.lang.Object

Public constructors

AppWidgetProvider

Added in API level 3
AppWidgetProvider ()

Constructor to initialize AppWidgetProvider.

Public methods

onAppWidgetOptionsChanged

Added in API level 16
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 Context: The Context in which this receiver is running.
appWidgetManager AppWidgetManager: A AppWidgetManager object you can call updateAppWidget(ComponentName, RemoteViews) on.
appWidgetId int: The appWidgetId of the widget whose size changed.
newOptions Bundle: The appWidgetId of the widget whose size changed.

See also:

onDeleted

Added in API level 3
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.

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

See also:

onDisabled

Added in API level 3
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.

Parameters
context Context: The Context in which this receiver is running.

See also:

onEnabled

Added in API level 3
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.

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 Context: The Context in which this receiver is running.

See also:

onReceive

Added in API level 3
void onReceive (Context context, 
                Intent intent)

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

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

onRestored

Added in API level 21
void onRestored (Context context, 
                int[] oldWidgetIds, 
                int[] newWidgetIds)

Called in response to the ACTION_APPWIDGET_RESTORED broadcast when instances of this AppWidget provider have been restored from backup. If your provider maintains any persistent data about its widget instances, override this method to remap the old AppWidgetIds to the new values and update any other app state that may be relevant.

This callback will be followed immediately by a call to onUpdate(Context, AppWidgetManager, int[]) so your provider can immediately generate new RemoteViews suitable for its newly-restored set of instances.

onUpdate

Added in API level 3
void onUpdate (Context context, 
                AppWidgetManager appWidgetManager, 
                int[] appWidgetIds)

Called in response to the ACTION_APPWIDGET_UPDATE and ACTION_APPWIDGET_RESTORED broadcasts 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 Context: The Context in which this receiver is running.
appWidgetManager AppWidgetManager: A AppWidgetManager object you can call updateAppWidget(ComponentName, RemoteViews) on.
appWidgetIds int: 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.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.