# AppWidgetManagerCompat

Added in 1.0.0

*** ** * ** ***

<br />

```
public final class AppWidgetManagerCompat
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html` | `https://developer.android.com/reference/androidx/core/widget/AppWidgetManagerCompat#createExactSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/appwidget/AppWidgetManager.html appWidgetManager, int appWidgetId, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory )` Creates a `https://developer.android.com/reference/android/widget/RemoteViews.html` associated with each size assigned to the app widget by `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html`, invoking `https://developer.android.com/reference/androidx/core/widget/package-summary#createExactSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.Function1)` to create each alternative view. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html` | `https://developer.android.com/reference/androidx/core/widget/AppWidgetManagerCompat#createResponsiveSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.collections.Collection,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/appwidget/AppWidgetManager.html appWidgetManager, int appWidgetId, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat> dpSizes, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory )` Creating a `https://developer.android.com/reference/android/widget/RemoteViews.html` associated with each size provided in `https://developer.android.com/reference/androidx/core/widget/package-summary#createResponsiveSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`. |
| `static final void` | `https://developer.android.com/reference/androidx/core/widget/AppWidgetManagerCompat#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/appwidget/AppWidgetManager.html receiver, int appWidgetId, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory )` Updates the app widget with `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.Function1)`, creating a `https://developer.android.com/reference/android/widget/RemoteViews.html` for each size assigned to the app widget by `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html`, invoking `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.Function1)` to create each alternative view. |
| `static final void` | `https://developer.android.com/reference/androidx/core/widget/AppWidgetManagerCompat#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/appwidget/AppWidgetManager.html receiver, int appWidgetId, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat> dpSizes, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory )` Updates the app widget with `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`, creating a `https://developer.android.com/reference/android/widget/RemoteViews.html` for each size provided in `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`. |

## Public methods

### createExactSizeAppWidget

Artifact: [androidx.core:core-remoteviews](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/widget/AppWidgetManagerCompat.kt+function:createExactSizeAppWidget)

```
public static final @NonNull RemoteViews createExactSizeAppWidget(
    @NonNull AppWidgetManager appWidgetManager,
    int appWidgetId,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)
```

Creates a `https://developer.android.com/reference/android/widget/RemoteViews.html` associated with each size assigned to the app widget by `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html`, invoking `https://developer.android.com/reference/androidx/core/widget/package-summary#createExactSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.Function1)` to create each alternative view.

This provides ["exact" sizing](https://developer.android.com/guide/topics/appwidgets/layouts#provide-exact-layouts) , which allows you to tailor your app widget appearance to the exact size at which it is displayed. If you are only concerned with a small number of size thresholds, it is preferable to use "responsive" sizing by providing a fixed set of sizes that your app widget supports.

As your `https://developer.android.com/reference/androidx/core/widget/package-summary#createExactSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.Function1)` may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html#updateAppWidget(android.content.ComponentName, android.widget.RemoteViews)` during both `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onUpdate(android.content.Context, android.appwidget.AppWidgetManager, int[])` and `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onAppWidgetOptionsChanged(android.content.Context, android.appwidget.AppWidgetManager, int, android.os.Bundle)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/appwidget/AppWidgetManager.html appWidgetManager` | the `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html` to provide information about `https://developer.android.com/reference/androidx/core/widget/package-summary#createExactSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.Function1)` |
| `int appWidgetId` | the id of the app widget |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory` | a function to create a `https://developer.android.com/reference/android/widget/RemoteViews.html` for a given width and height (in dp) |

### createResponsiveSizeAppWidget

Artifact: [androidx.core:core-remoteviews](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/widget/AppWidgetManagerCompat.kt+function:createResponsiveSizeAppWidget)

```
public static final @NonNull RemoteViews createResponsiveSizeAppWidget(
    @NonNull AppWidgetManager appWidgetManager,
    int appWidgetId,
    @NonNull Collection<@NonNull SizeFCompat> dpSizes,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)
```

Creating a `https://developer.android.com/reference/android/widget/RemoteViews.html` associated with each size provided in `https://developer.android.com/reference/androidx/core/widget/package-summary#createResponsiveSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`.

This provides ["responsive" sizing](https://developer.android.com/guide/topics/appwidgets/layouts#provide-responsive-layouts) , which allows for smoother resizing and a more consistent experience across different host configurations.

As your `https://developer.android.com/reference/androidx/core/widget/package-summary#createResponsiveSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.collections.Collection,kotlin.Function1)` may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html#updateAppWidget(android.content.ComponentName, android.widget.RemoteViews)` during both `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onUpdate(android.content.Context, android.appwidget.AppWidgetManager, int[])` and `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onAppWidgetOptionsChanged(android.content.Context, android.appwidget.AppWidgetManager, int, android.os.Bundle)`. If your app's minSdk is 31 or higher, it is only necessary to call `updateAppWidget` during `onUpdate`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/appwidget/AppWidgetManager.html appWidgetManager` | the `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html` to provide information about `https://developer.android.com/reference/androidx/core/widget/package-summary#createResponsiveSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.collections.Collection,kotlin.Function1)` |
| `int appWidgetId` | the id of the app widget |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat> dpSizes` | a collection of sizes (in dp) that your app widget supports. Must not be empty or contain more than 16 elements. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory` | a function to create a `https://developer.android.com/reference/android/widget/RemoteViews.html` for a given width and height (in dp). It is guaranteed that `https://developer.android.com/reference/androidx/core/widget/package-summary#createResponsiveSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.collections.Collection,kotlin.Function1)` will only ever be called with the values provided in `https://developer.android.com/reference/androidx/core/widget/package-summary#createResponsiveSizeAppWidget(android.appwidget.AppWidgetManager,kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`. |

### updateAppWidget

Artifact: [androidx.core:core-remoteviews](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/widget/AppWidgetManagerCompat.kt+function:updateAppWidget)

```
public static final void updateAppWidget(
    @NonNull AppWidgetManager receiver,
    int appWidgetId,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)
```

Updates the app widget with `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.Function1)`, creating a `https://developer.android.com/reference/android/widget/RemoteViews.html` for each size assigned to the app widget by `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html`, invoking `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.Function1)` to create each alternative view.

This provides ["exact" sizing](https://developer.android.com/guide/topics/appwidgets/layouts#provide-exact-layouts) , which allows you to tailor your app widget appearance to the exact size at which it is displayed. If you are only concerned with a small number of size thresholds, it is preferable to use "responsive" sizing by providing a fixed set of sizes that your app widget supports.

As your `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.Function1)` may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call this function during both `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onUpdate(android.content.Context, android.appwidget.AppWidgetManager, int[])` and `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onAppWidgetOptionsChanged(android.content.Context, android.appwidget.AppWidgetManager, int, android.os.Bundle)`.

| Parameters |
|---|---|
| `int appWidgetId` | the id of the app widget |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory` | a function to create a `https://developer.android.com/reference/android/widget/RemoteViews.html` for a given width and height (in dp) |

### updateAppWidget

Artifact: [androidx.core:core-remoteviews](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/widget/AppWidgetManagerCompat.kt+function:updateAppWidget)

```
public static final void updateAppWidget(
    @NonNull AppWidgetManager receiver,
    int appWidgetId,
    @NonNull Collection<@NonNull SizeFCompat> dpSizes,
    @NonNull Function1<@NonNull SizeFCompat, @NonNull RemoteViews> factory
)
```

Updates the app widget with `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`, creating a `https://developer.android.com/reference/android/widget/RemoteViews.html` for each size provided in `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`.

This provides ["responsive" sizing](https://developer.android.com/guide/topics/appwidgets/layouts#provide-responsive-layouts) , which allows for smoother resizing and a more consistent experience across different host configurations.

As your `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)` may be invoked multiple times, if there is expensive computation of state that is shared among each size, it is recommended to perform that computation before calling this and cache the results as necessary.

To handle resizing of your app widget, it is necessary to call this function during both `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onUpdate(android.content.Context, android.appwidget.AppWidgetManager, int[])` and `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onAppWidgetOptionsChanged(android.content.Context, android.appwidget.AppWidgetManager, int, android.os.Bundle)`. If your app's minSdk is 31 or higher, it is only necessary to call this function during `onUpdate`.

| Parameters |
|---|---|
| `int appWidgetId` | the id of the app widget |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat> dpSizes` | a collection of sizes (in dp) that your app widget supports. Must not be empty or contain more than 16 elements. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/SizeFCompat, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/widget/RemoteViews.html> factory` | a function to create a `https://developer.android.com/reference/android/widget/RemoteViews.html` for a given width and height (in dp). It is guaranteed that `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)` will only ever be called with the values provided in `https://developer.android.com/reference/androidx/core/widget/package-summary#(android.appwidget.AppWidgetManager).updateAppWidget(kotlin.Int,kotlin.collections.Collection,kotlin.Function1)`. |