Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/appwidget/AppWidgetHost#pubctors) \| [Methods](https://developer.android.com/reference/android/appwidget/AppWidgetHost#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/appwidget/AppWidgetHost#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/appwidget/AppWidgetHost#inhmethods)

# AppWidgetHost

*** ** * ** ***


`
public


class
AppWidgetHost
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.appwidget.AppWidgetHost |

<br />

*** ** * ** ***

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 ||
|---|---|
| ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#AppWidgetHost(android.content.Context,%20int)(https://developer.android.com/reference/android/content/Context context, int hostId) ` |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#allocateAppWidgetId()() ` Get a appWidgetId for a host in the calling process. |
| ` final https://developer.android.com/reference/android/appwidget/AppWidgetHostView` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#createView(android.content.Context,%20int,%20android.appwidget.AppWidgetProviderInfo)(https://developer.android.com/reference/android/content/Context context, int appWidgetId, https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo appWidget) ` Create the AppWidgetHostView for the given widget. |
| ` static void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#deleteAllHosts()() ` Remove all records about all hosts for your package. |
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#deleteAppWidgetId(int)(int appWidgetId) ` Stop listening to changes for this AppWidget. |
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#deleteHost()() ` Remove all records about this host from the AppWidget manager. |
| ` int[]` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#getAppWidgetIds()() ` Gets a list of all the appWidgetIds that are bound to the current host |
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#onAppWidgetRemoved(int)(int appWidgetId) ` Called when the app widget is removed for appWidgetId |
| ` final void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#startAppWidgetConfigureActivityForResult(android.app.Activity,%20int,%20int,%20int,%20android.os.Bundle)(https://developer.android.com/reference/android/app/Activity activity, int appWidgetId, int intentFlags, int requestCode, https://developer.android.com/reference/android/os/Bundle options) ` Starts an app widget provider configure activity for result on behalf of the caller. |
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#startListening()() ` Start receiving onAppWidgetChanged calls for your AppWidgets. |
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#stopListening()() ` Stop receiving onAppWidgetChanged calls for your AppWidgets. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#clearViews()() ` Clear the list of Views that have been created by this AppWidgetHost. |
| ` https://developer.android.com/reference/android/appwidget/AppWidgetHostView` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#onCreateView(android.content.Context,%20int,%20android.appwidget.AppWidgetProviderInfo)(https://developer.android.com/reference/android/content/Context context, int appWidgetId, https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo appWidget) ` Called to create the AppWidgetHostView. Override to return a custom subclass if you need it. |
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#onProviderChanged(int,%20android.appwidget.AppWidgetProviderInfo)(int appWidgetId, https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo appWidget) ` Called when the AppWidget provider for a AppWidget has been upgraded to a new apk. |
| ` void` | ` https://developer.android.com/reference/android/appwidget/AppWidgetHost#onProvidersChanged()() ` Called when the set of available widgets changes (ie. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### AppWidgetHost

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AppWidgetHost (Context context, 
                int hostId)
```

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `hostId` | `int` <br /> |

## Public methods

### allocateAppWidgetId

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int allocateAppWidgetId ()
```

Get a appWidgetId for a host in the calling process.

<br />

| Returns ||
|---|---|
| `int` | a appWidgetId <br /> |

### createView

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final AppWidgetHostView createView (Context context, 
                int appWidgetId, 
                AppWidgetProviderInfo appWidget)
```

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

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `appWidgetId` | `int` <br /> |
| `appWidget` | `AppWidgetProviderInfo` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/appwidget/AppWidgetHostView` | <br /> |

### deleteAllHosts

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void deleteAllHosts ()
```

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.

<br />

<br />

### deleteAppWidgetId

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void deleteAppWidgetId (int appWidgetId)
```

Stop listening to changes for this AppWidget.

<br />

| Parameters ||
|---|---|
| `appWidgetId` | `int` <br /> |

### deleteHost

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void deleteHost ()
```

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.

<br />

<br />

### getAppWidgetIds

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int[] getAppWidgetIds ()
```

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

<br />

| Returns ||
|---|---|
| `int[]` | <br /> |

### onAppWidgetRemoved

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onAppWidgetRemoved (int appWidgetId)
```

Called when the app widget is removed for appWidgetId

<br />

### startAppWidgetConfigureActivityForResult

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void startAppWidgetConfigureActivityForResult (Activity activity, 
                int appWidgetId, 
                int intentFlags, 
                int requestCode, 
                Bundle options)
```

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 `https://developer.android.com/reference/android/app/Activity#onActivityResult(int,%20int,%20android.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.

<br />

<br />

| Parameters ||
|---|---|
| `activity` | `Activity`: The activity from which to start the configure one. This value cannot be `null`. <br /> |
| `appWidgetId` | `int`: The bound app widget whose provider's config activity to start. <br /> |
| `intentFlags` | `int`: Optional intent flags. <br /> |
| `requestCode` | `int`: Optional request code retuned with the result. <br /> |
| `options` | `Bundle`: This value may be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/content/ActivityNotFoundException` | If the activity is not found. |

**See also:**

- `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo#getProfile()`

### startListening

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startListening ()
```

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

<br />

### stopListening

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void stopListening ()
```

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

<br />

## Protected methods

### clearViews

Added in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void clearViews ()
```

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

<br />

### onCreateView

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected AppWidgetHostView onCreateView (Context context, 
                int appWidgetId, 
                AppWidgetProviderInfo appWidget)
```

Called to create the AppWidgetHostView. Override to return a custom subclass if you
need it.

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `appWidgetId` | `int` <br /> |
| `appWidget` | `AppWidgetProviderInfo` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/appwidget/AppWidgetHostView` | <br /> |

### onProviderChanged

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onProviderChanged (int appWidgetId, 
                AppWidgetProviderInfo appWidget)
```

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

<br />

| Parameters ||
|---|---|
| `appWidgetId` | `int` <br /> |
| `appWidget` | `AppWidgetProviderInfo` <br /> |

### onProvidersChanged

Added in [API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onProvidersChanged ()
```

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

<br />