public class AppWidgetProvider extends BroadcastReceiver
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(android.content.Context, android.appwidget.AppWidgetManager, int[])
, onDeleted(android.content.Context, int[])
,
onEnabled(android.content.Context)
or onDisabled(android.content.Context)
methods to implement your own AppWidget functionality.
For more information about how to write an app widget provider, read the App Widgets developer guide.
BroadcastReceiver.PendingResult
Constructor and Description |
---|
AppWidgetProvider()
Constructor to initialize AppWidgetProvider.
|
Modifier and Type | Method and Description |
---|---|
void |
onAppWidgetOptionsChanged(Context context,
AppWidgetManager appWidgetManager,
int appWidgetId,
Bundle newOptions)
Called in response to the
AppWidgetManager.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
AppWidgetManager.ACTION_APPWIDGET_DELETED broadcast when
one or more AppWidget instances have been deleted. |
void |
onDisabled(Context context)
Called in response to the
AppWidgetManager.ACTION_APPWIDGET_DISABLED broadcast, which
is sent when the last AppWidget instance for this provider is deleted. |
void |
onEnabled(Context context)
Called in response to the
AppWidgetManager.ACTION_APPWIDGET_ENABLED broadcast when
the a AppWidget for this provider is instantiated. |
void |
onReceive(Context context,
Intent intent)
Implements
BroadcastReceiver.onReceive(android.content.Context, android.content.Intent) to dispatch calls to the various
other methods on AppWidgetProvider. |
void |
onRestored(Context context,
int[] oldWidgetIds,
int[] newWidgetIds)
Called in response to the
AppWidgetManager.ACTION_APPWIDGET_RESTORED broadcast
when instances of this AppWidget provider have been restored from backup. |
void |
onUpdate(Context context,
AppWidgetManager appWidgetManager,
int[] appWidgetIds)
Called in response to the
AppWidgetManager.ACTION_APPWIDGET_UPDATE and
AppWidgetManager.ACTION_APPWIDGET_RESTORED broadcasts when this AppWidget
provider is being asked to provide RemoteViews
for a set of AppWidgets. |
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getPendingResult, getResultCode, getResultData, getResultExtras, getSendingUserId, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setPendingResult, setResult, setResultCode, setResultData, setResultExtras
public AppWidgetProvider()
public void onReceive(Context context, Intent intent)
BroadcastReceiver.onReceive(android.content.Context, android.content.Intent)
to dispatch calls to the various
other methods on AppWidgetProvider.onReceive
in class BroadcastReceiver
context
- The Context in which the receiver is running.intent
- The Intent being received.public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
AppWidgetManager.ACTION_APPWIDGET_UPDATE
and
AppWidgetManager.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.
context
- The Context
in which this receiver is
running.appWidgetManager
- A AppWidgetManager
object you can call AppWidgetManager.updateAppWidget(int[], android.widget.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.AppWidgetManager.ACTION_APPWIDGET_UPDATE
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)
AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED
broadcast when this widget has been layed out at a new size.
context
- The Context
in which this receiver is
running.appWidgetManager
- A AppWidgetManager
object you can call AppWidgetManager.updateAppWidget(int[], android.widget.RemoteViews)
on.appWidgetId
- The appWidgetId of the widget whose size changed.newOptions
- The appWidgetId of the widget whose size changed.AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED
public void onDeleted(Context context, int[] appWidgetIds)
AppWidgetManager.ACTION_APPWIDGET_DELETED
broadcast when
one or more AppWidget instances have been deleted. Override this method to implement
your own AppWidget functionality.
context
- The Context
in which this receiver is
running.appWidgetIds
- The appWidgetIds that have been deleted from their host.AppWidgetManager.ACTION_APPWIDGET_DELETED
public void onEnabled(Context context)
AppWidgetManager.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,
AppWidgetManager.ACTION_APPWIDGET_DISABLED
is sent by the AppWidget manager, and
onDisabled(android.content.Context)
is called. If after that, an AppWidget for this provider is created
again, onEnabled() will be called again.context
- The Context
in which this receiver is
running.AppWidgetManager.ACTION_APPWIDGET_ENABLED
public void onDisabled(Context context)
AppWidgetManager.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.
context
- The Context
in which this receiver is
running.AppWidgetManager.ACTION_APPWIDGET_DISABLED
public void onRestored(Context context, int[] oldWidgetIds, int[] newWidgetIds)
AppWidgetManager.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(android.content.Context, android.appwidget.AppWidgetManager, int[])
so your
provider can immediately generate new RemoteViews suitable for its newly-restored set
of instances.
context
- oldWidgetIds
- newWidgetIds
-