AppWidgetProvider
open class AppWidgetProvider : BroadcastReceiver
kotlin.Any | ||
↳ | 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
, onDeleted
, onEnabled
or onDisabled
methods to implement your own AppWidget functionality.
Summary
Public constructors | |
---|---|
Constructor to initialize AppWidgetProvider. |
Public methods | |
---|---|
open Unit |
onAppWidgetOptionsChanged(context: Context!, appWidgetManager: AppWidgetManager!, appWidgetId: Int, newOptions: Bundle!) Called in response to the |
open Unit |
Called in response to the |
open Unit |
onDisabled(context: Context!) Called in response to the |
open Unit |
Called in response to the |
open Unit |
Implements |
open Unit |
onRestored(context: Context!, oldWidgetIds: IntArray!, newWidgetIds: IntArray!) Called in response to the |
open Unit |
onUpdate(context: Context!, appWidgetManager: AppWidgetManager!, appWidgetIds: IntArray!) Called in response to the |
Inherited functions | |
---|---|
Public constructors
AppWidgetProvider
AppWidgetProvider()
Constructor to initialize AppWidgetProvider.
Public methods
onAppWidgetOptionsChanged
open fun onAppWidgetOptionsChanged(
context: Context!,
appWidgetManager: AppWidgetManager!,
appWidgetId: Int,
newOptions: Bundle!
): Unit
Called in response to the AppWidgetManager#ACTION_APPWIDGET_OPTIONS_CHANGED
broadcast when this widget has been layed out at a new size or its options changed via AppWidgetManager#updateAppWidgetOptions
. {@more}
Parameters | |
---|---|
context |
Context!: The Context in which this receiver is running. |
appWidgetManager |
AppWidgetManager!: A AppWidgetManager object you can call android.appwidget.AppWidgetManager#updateAppWidget on. |
appWidgetId |
Int: The appWidgetId of the widget whose size changed. |
newOptions |
Bundle!: The new options of the changed widget. |
onDeleted
open fun onDeleted(
context: Context!,
appWidgetIds: IntArray!
): Unit
Called in response to the AppWidgetManager#ACTION_APPWIDGET_DELETED
broadcast when one or more AppWidget instances have been deleted. Override this method to implement your own AppWidget functionality. {@more}
Parameters | |
---|---|
context |
Context!: The Context in which this receiver is running. |
appWidgetIds |
IntArray!: The appWidgetIds that have been deleted from their host. |
onDisabled
open fun onDisabled(context: Context!): Unit
Called in response to the 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}
Parameters | |
---|---|
context |
Context!: The Context in which this receiver is running. |
onEnabled
open fun onEnabled(context: Context!): Unit
Called in response to the 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, AppWidgetManager#ACTION_APPWIDGET_DISABLED
is sent by the AppWidget manager, and onDisabled
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. |
onReceive
open fun onReceive(
context: Context!,
intent: Intent!
): Unit
Implements BroadcastReceiver#onReceive
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
open fun onRestored(
context: Context!,
oldWidgetIds: IntArray!,
newWidgetIds: IntArray!
): Unit
Called in response to the 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
so your provider can immediately generate new RemoteViews suitable for its newly-restored set of instances.
In addition, you should set AppWidgetManager#OPTION_APPWIDGET_RESTORE_COMPLETED
to true indicate if a widget has been restored successfully from the provider's side. {@more}
Parameters | |
---|---|
context |
Context!: |
oldWidgetIds |
IntArray!: |
newWidgetIds |
IntArray!: |
onUpdate
open fun onUpdate(
context: Context!,
appWidgetManager: AppWidgetManager!,
appWidgetIds: IntArray!
): Unit
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. Override this method to implement your own AppWidget functionality. {@more}
Parameters | |
---|---|
context |
Context!: The Context in which this receiver is running. |
appWidgetManager |
AppWidgetManager!: A AppWidgetManager object you can call android.appwidget.AppWidgetManager#updateAppWidget on. |
appWidgetIds |
IntArray!: 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. |