# GlanceAdaptiveWidgetReceiver

Artifact: [androidx.glance.adaptive:adaptive-appwidget](https://developer.android.com/jetpack/androidx/releases/glance-adaptive) [View Source](https://cs.android.com/search?q=file:androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver.kt+class:androidx.glance.adaptive.appwidget.GlanceAdaptiveWidgetReceiver) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/glance-adaptive#1.0.0-alpha04)


```
abstract class GlanceAdaptiveWidgetReceiver : AppWidgetProvider
```

<br />

|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) ||||
| ↳ | [android.content.BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html) |||
|   | ↳ | [android.appwidget.AppWidgetProvider](https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html) ||
|   |   | ↳ | [androidx.glance.adaptive.appwidget.GlanceAdaptiveWidgetReceiver](https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver) |

*** ** * ** ***

`https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html` using Glance Adaptive to process widget lifecycle events and updates.

Subclass this receiver to associate a widget declared in `AndroidManifest.xml` with a `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#widgetName()`. Rather than providing a custom `GlanceAppWidget` composable layout, applications push data via `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/core/GlanceAdaptiveWidgetManager#pushUpdate(kotlin.String,androidx.glance.adaptive.core.ui.templates.GlanceAdaptiveTemplate)`, and the library adapts and renders the layout for each target surface.

This should typically be used as:

```kotlin
class MyGlanceAdaptiveWidgetReceiver : GlanceAdaptiveWidgetReceiver() {
    override val widgetName: String = "my_widget"
    override suspend fun onUpdate(context: Context) {
        GlanceAdaptiveWidgetManager(context).pushUpdate(
            widgetName = widgetName,
            currentData = ...
        )
    }
}
```

Include the `https://developer.android.com/reference/android/content/Intent.html#ACTION_LOCALE_CHANGED` action in the receiver declaration in `AndroidManifest.xml` so that widgets are updated when the device locale changes:

```kotlin
<receiver android:name=".MyGlanceAdaptiveWidgetReceiver" android:exported="true">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        <action android:name="android.intent.action.LOCALE_CHANGED" />
    </intent-filter>
</receiver>
```

Note: If you override any methods of this class or `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html`, ensure you call their superclass implementation. For the `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onUpdate(android.content.Context)` flow managed by this receiver, do not call `https://developer.android.com/reference/android/content/BroadcastReceiver.html#goAsync()` manually, as broadcast lifecycle completion is handled by the superclass implementation.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#ACTION_DEBUG_UPDATE()` Broadcast action to force a debug update of the Glance Adaptive widget via adb: `adb shell am broadcast -a androidx.glance.adaptive.appwidget.action.DEBUG_UPDATE -n APP/COMPONENT` |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#EXTRA_WIDGET_ID()` Key for storing the widget instance identifier in the `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html` widget options bundle. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#GlanceAdaptiveWidgetReceiver()()` |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onAppWidgetOptionsChanged(android.content.Context,android.appwidget.AppWidgetManager,kotlin.Int,android.os.Bundle)( context: https://developer.android.com/reference/android/content/Context.html, appWidgetManager: https://developer.android.com/reference/android/appwidget/AppWidgetManager.html, appWidgetId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, newOptions: https://developer.android.com/reference/android/os/Bundle.html )` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onDeleted(android.content.Context,kotlin.IntArray)(context: https://developer.android.com/reference/android/content/Context.html, appWidgetIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html)` Called when widget instances are deleted. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onReceive(android.content.Context,android.content.Intent)(context: https://developer.android.com/reference/android/content/Context.html, intent: https://developer.android.com/reference/android/content/Intent.html)` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onRestored(android.content.Context,kotlin.IntArray,kotlin.IntArray)( context: https://developer.android.com/reference/android/content/Context.html, oldWidgetIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html, newWidgetIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html )` |
| `abstract suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onUpdate(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Called on a background coroutine when the system requests an update for this widget (such as on initial placement from the widget picker, device boot, locale or size changes, or periodic update alarms). |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onUpdate(android.content.Context,android.appwidget.AppWidgetManager,kotlin.IntArray)( context: https://developer.android.com/reference/android/content/Context.html, appWidgetManager: https://developer.android.com/reference/android/appwidget/AppWidgetManager.html, appWidgetIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html )` |

| ### Public properties |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#coroutineContext()` Override `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#coroutineContext()` to provide a custom `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` in which background update tasks are executed. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#widgetName()` Unique developer-defined identifier used to associate this receiver with a specific widget definition (e.g., "my_widget"). |

### Inherited functions

From [android.appwidget.AppWidgetProvider](https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onDisabled(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html#onEnabled(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` From [android.content.BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#clearAbortBroadcast()()` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getResultExtras(boolean)(makeMap: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` `https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#goAsync()()` `https://developer.android.com/reference/android/os/IBinder.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#peekService(android.content.Context, android.content.Intent)(myContext: https://developer.android.com/reference/android/content/Context.html, service: https://developer.android.com/reference/android/content/Intent.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setOrderedHint(boolean)(isOrdered: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResult(int, java.lang.String, android.os.Bundle)(code: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, extras: https://developer.android.com/reference/android/os/Bundle.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResultExtras(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html)`

### Inherited properties

From [android.content.BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#debugUnregister` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#isInitialStickyBroadcast` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#isOrderedBroadcast` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#resultCode` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#resultData` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#sentFromPackage` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#sentFromUid`

## Constants

### ACTION_DEBUG_UPDATE

```
const val ACTION_DEBUG_UPDATE: String
```

Broadcast action to force a debug update of the Glance Adaptive widget via adb: `adb shell am broadcast -a androidx.glance.adaptive.appwidget.action.DEBUG_UPDATE -n APP/COMPONENT`

To target specific widget IDs, pass `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html#EXTRA_APPWIDGET_IDS`: `adb shell am broadcast -a androidx.glance.adaptive.appwidget.action.DEBUG_UPDATE -n APP/COMPONENT --eia appWidgetIds 1,2`

### EXTRA_WIDGET_ID

```
const val EXTRA_WIDGET_ID: String
```

Key for storing the widget instance identifier in the `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html` widget options bundle.

## Public constructors

### GlanceAdaptiveWidgetReceiver

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/glance-adaptive#1.0.0-alpha04)

```
GlanceAdaptiveWidgetReceiver()
```

## Public functions

### onAppWidgetOptionsChanged

```
@CallSuper
open fun onAppWidgetOptionsChanged(
    context: Context,
    appWidgetManager: AppWidgetManager,
    appWidgetId: Int,
    newOptions: Bundle
): Unit
```

### onDeleted

```
@CallSuper
open fun onDeleted(context: Context, appWidgetIds: IntArray): Unit
```

Called when widget instances are deleted. Removes cached widget options associated with the deleted `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#onDeleted(android.content.Context,kotlin.IntArray)` from the internal cache.

If this method is overridden, `super.onDeleted` must be called to ensure internal cache cleanup.

### onReceive

```
open fun onReceive(context: Context, intent: Intent): Unit
```

### onRestored

```
@CallSuper
open fun onRestored(
    context: Context,
    oldWidgetIds: IntArray,
    newWidgetIds: IntArray
): Unit
```

### onUpdate

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/glance-adaptive#1.0.0-alpha04)

```
abstract suspend fun onUpdate(context: Context): Unit
```

Called on a background coroutine when the system requests an update for this widget (such as on initial placement from the widget picker, device boot, locale or size changes, or periodic update alarms).

Implement this method to fetch your widget data and call `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/core/GlanceAdaptiveWidgetManager#pushUpdate(kotlin.String,androidx.glance.adaptive.core.ui.templates.GlanceAdaptiveTemplate)`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The application Context. |

### onUpdate

```
@CallSuper
open fun onUpdate(
    context: Context,
    appWidgetManager: AppWidgetManager,
    appWidgetIds: IntArray
): Unit
```

## Public properties

### coroutineContext

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/glance-adaptive#1.0.0-alpha04)

```
open val coroutineContext: CoroutineContext
```

Override `https://developer.android.com/reference/kotlin/androidx/glance/adaptive/appwidget/GlanceAdaptiveWidgetReceiver#coroutineContext()` to provide a custom `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` in which background update tasks are executed.

This context is used when launching the asynchronous broadcast block. It should include a dispatcher suitable for background work (e.g., `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html` or `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html`).

### widgetName

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/glance-adaptive#1.0.0-alpha04)

```
abstract val widgetName: String
```

Unique developer-defined identifier used to associate this receiver with a specific widget definition (e.g., "my_widget").

This identifier should correspond to the widget template definition or layout configuration registered with the adaptive widget framework.