Added in API level 3

AppWidgetHost


open class AppWidgetHost
kotlin.Any
   ↳ android.appwidget.AppWidgetHost

AppWidgetHost provides the interaction with the AppWidget service for apps, like the home screen, that want to embed AppWidgets in their UI.

Summary

Public constructors
AppWidgetHost(context: Context!, hostId: Int)

Public methods
open Int

Get a appWidgetId for a host in the calling process.

AppWidgetHostView!
createView(context: Context!, appWidgetId: Int, appWidget: AppWidgetProviderInfo!)

Create the AppWidgetHostView for the given widget.

open static Unit

Remove all records about all hosts for your package.

open Unit
deleteAppWidgetId(appWidgetId: Int)

Stop listening to changes for this AppWidget.

open Unit

Remove all records about this host from the AppWidget manager.

open IntArray!

Gets a list of all the appWidgetIds that are bound to the current host

open Unit
onAppWidgetRemoved(appWidgetId: Int)

Called when the app widget is removed for appWidgetId

Unit
startAppWidgetConfigureActivityForResult(activity: Activity, appWidgetId: Int, intentFlags: Int, requestCode: Int, options: Bundle?)

Starts an app widget provider configure activity for result on behalf of the caller.

open Unit

Start receiving onAppWidgetChanged calls for your AppWidgets.

open Unit

Stop receiving onAppWidgetChanged calls for your AppWidgets.

Protected methods
open Unit

Clear the list of Views that have been created by this AppWidgetHost.

open AppWidgetHostView!
onCreateView(context: Context!, appWidgetId: Int, appWidget: AppWidgetProviderInfo!)

Called to create the AppWidgetHostView.

open Unit
onProviderChanged(appWidgetId: Int, appWidget: AppWidgetProviderInfo!)

Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.

open Unit

Called when the set of available widgets changes (ie. widget containing packages are added, updated or removed, or widget components are enabled or disabled.)

Public constructors

AppWidgetHost

Added in API level 3
AppWidgetHost(
    context: Context!,
    hostId: Int)

Public methods

allocateAppWidgetId

Added in API level 3
open fun allocateAppWidgetId(): Int

Get a appWidgetId for a host in the calling process.

Return
Int a appWidgetId

createView

Added in API level 3
fun createView(
    context: Context!,
    appWidgetId: Int,
    appWidget: AppWidgetProviderInfo!
): AppWidgetHostView!

Create the AppWidgetHostView for the given widget. The AppWidgetHost retains a pointer to the newly-created View.

deleteAllHosts

Added in API level 3
open static fun deleteAllHosts(): Unit

Remove all records about all hosts for your package.

  • Call this when initializing your database, as it might be because of a data wipe.
  • Call this to have the AppWidget manager release all resources associated with your host. Any future calls about this host will cause the records to be re-allocated.

deleteAppWidgetId

Added in API level 3
open fun deleteAppWidgetId(appWidgetId: Int): Unit

Stop listening to changes for this AppWidget.

deleteHost

Added in API level 3
open fun deleteHost(): Unit

Remove all records about this host from the AppWidget manager.

  • Call this when initializing your database, as it might be because of a data wipe.
  • Call this to have the AppWidget manager release all resources associated with your host. Any future calls about this host will cause the records to be re-allocated.

getAppWidgetIds

Added in API level 26
open fun getAppWidgetIds(): IntArray!

Gets a list of all the appWidgetIds that are bound to the current host

onAppWidgetRemoved

Added in API level 30
open fun onAppWidgetRemoved(appWidgetId: Int): Unit

Called when the app widget is removed for appWidgetId

Parameters
appWidgetId Int:

startAppWidgetConfigureActivityForResult

Added in API level 21
fun startAppWidgetConfigureActivityForResult(
    activity: Activity,
    appWidgetId: Int,
    intentFlags: Int,
    requestCode: Int,
    options: Bundle?
): Unit

Starts an app widget provider configure activity for result on behalf of the caller. Use this method if the provider is in another profile as you are not allowed to start an activity in another profile. You can optionally provide a request code that is returned in Activity#onActivityResult(int, int, android.content.Intent) and an options bundle to be passed to the started activity.

Note that the provided app widget has to be bound for this method to work.

Parameters
activity Activity: The activity from which to start the configure one. This value cannot be null.
appWidgetId Int: The bound app widget whose provider's config activity to start.
requestCode Int: Optional request code retuned with the result.
intentFlags Int: Optional intent flags.
options Bundle?: This value may be null.
Exceptions
android.content.ActivityNotFoundException If the activity is not found.

startListening

Added in API level 3
open fun startListening(): Unit

Start receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity becomes visible, i.e. from onStart() in your Activity.

stopListening

Added in API level 3
open fun stopListening(): Unit

Stop receiving onAppWidgetChanged calls for your AppWidgets. Call this when your activity is no longer visible, i.e. from onStop() in your Activity.

Protected methods

clearViews

Added in API level 11
protected open fun clearViews(): Unit

Clear the list of Views that have been created by this AppWidgetHost.

onCreateView

Added in API level 3
protected open fun onCreateView(
    context: Context!,
    appWidgetId: Int,
    appWidget: AppWidgetProviderInfo!
): AppWidgetHostView!

Called to create the AppWidgetHostView. Override to return a custom subclass if you need it. {@more}

onProviderChanged

Added in API level 3
protected open fun onProviderChanged(
    appWidgetId: Int,
    appWidget: AppWidgetProviderInfo!
): Unit

Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.

onProvidersChanged

Added in API level 17
protected open fun onProvidersChanged(): Unit

Called when the set of available widgets changes (ie. widget containing packages are added, updated or removed, or widget components are enabled or disabled.)