AppWidgetProviderpublic class AppWidgetProvider extends android.content.BroadcastReceiver A conveience class to aid in implementing an AppWidget provider.
Everything you can do with AppWidgetProvider, you can do with a regular {@link BroadcastReceiver}.
AppWidgetProvider merely parses the relevant fields out of the Intent that is received in
{@link #onReceive(Context,Intent) onReceive(Context,Intent)}, and calls hook methods
with the received extras.
Extend this class and override one or more of the {@link #onUpdate}, {@link #onDeleted},
{@link #onEnabled} or {@link #onDisabled} methods to implement your own AppWidget functionality.
Sample Code
For an example of how to write a AppWidget provider, see the
android.appwidget
package overview. |
Constructors Summary |
---|
public AppWidgetProvider()Constructor to initialize AppWidgetProvider.
|
Methods Summary |
---|
public void | onDeleted(android.content.Context context, int[] appWidgetIds)Called in response to the {@link AppWidgetManager#ACTION_APPWIDGET_DELETED} broadcast when
one or more AppWidget instances have been deleted. Override this method to implement
your own AppWidget functionality.
{@more}
| public void | onDisabled(android.content.Context context)Called in response to the {@link 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.
{@more}
| public void | onEnabled(android.content.Context context)Called in response to the {@link AppWidgetManager#ACTION_APPWIDGET_ENABLED} broadcast when
the a AppWidget for this provider is instantiated. Override this method to implement your
own AppWidget functionality.
{@more}
When the last AppWidget for this provider is deleted,
{@link AppWidgetManager#ACTION_APPWIDGET_DISABLED} is sent by the AppWidget manager, and
{@link #onDisabled} is called. If after that, an AppWidget for this provider is created
again, onEnabled() will be called again.
| public void | onReceive(android.content.Context context, android.content.Intent intent)Implements {@link BroadcastReceiver#onReceive} to dispatch calls to the various
other methods on AppWidgetProvider.
// Protect against rogue update broadcasts (not really a security issue,
// just filter bad broacasts out so subclasses are less likely to crash).
String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
Bundle extras = intent.getExtras();
if (extras != null) {
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (appWidgetIds != null && appWidgetIds.length > 0) {
this.onUpdate(context, AppWidgetManager.getInstance(context), appWidgetIds);
}
}
}
else if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
Bundle extras = intent.getExtras();
if (extras != null) {
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (appWidgetIds != null && appWidgetIds.length > 0) {
this.onDeleted(context, appWidgetIds);
}
}
}
else if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
this.onEnabled(context);
}
else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
this.onDisabled(context);
}
| public void | onUpdate(android.content.Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)Called in response to the {@link AppWidgetManager#ACTION_APPWIDGET_UPDATE} broadcast when
this AppWidget provider is being asked to provide {@link android.widget.RemoteViews RemoteViews}
for a set of AppWidgets. Override this method to implement your own AppWidget functionality.
{@more}
|
|