> Documentation index: https://developer.android.com/reference/llms.txt

# GlanceAdaptiveActionCallback

Artifact: [androidx.glance.adaptive:adaptive-core](https://developer.android.com/jetpack/androidx/releases/glance-adaptive.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/glance/adaptive/core/action/GlanceAdaptiveActionCallback.kt+class:androidx.glance.adaptive.core.action.GlanceAdaptiveActionCallback) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/glance-adaptive.md.txt#1.0.0-alpha06)


```
interface GlanceAdaptiveActionCallback
```

<br />

*** ** * ** ***

Handles interactive widget clicks in the background.

Implementations must have a public zero-argument constructor so the runtime can instantiate them when a `GlanceAdaptiveAction.CallbackAction` triggers.

Implement `onAction` to handle the user interaction and, if the widget UI needs to reflect the new state, call `androidx.glance.adaptive.core.GlanceAdaptiveWidgetManager.pushUpdate`.

`onAction` runs on a background thread while the click broadcast is handled, which the system gives 10 seconds to finish. If `onAction` has not returned after 9 seconds, it is cancelled and an error is logged. Cancellation can only stop suspending calls, so avoid blocking ones. Hand off longer work, for example to a foreground service or a job.

Exceptions thrown by `onAction` are not caught, as in a plain `android.content.BroadcastReceiver`: they crash the app. Catch the ones you expect, such as network errors. A `kotlinx.coroutines.CancellationException`, such as from an expired `withTimeout`, only ends the call, without being reported.

| See also |
|---|---|
| `GlanceAdaptiveAction.CallbackAction` |   |
| `pushUpdate` |   |

## Summary

| ### Public functions |
|---|---|
| `suspend Unit` | `onAction( context: Context, widgetName: String, widgetId: String?, parameters: Bundle )` Called on a background coroutine when the user triggers a `GlanceAdaptiveAction.CallbackAction`. |

## Public functions

### onAction

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

```
suspend fun onAction(
    context: Context,
    widgetName: String,
    widgetId: String?,
    parameters: Bundle
): Unit
```

Called on a background coroutine when the user triggers a `GlanceAdaptiveAction.CallbackAction`.

| Parameters |
|---|---|
| `context: Context` | application or broadcast `Context` executing the callback. |
| `widgetName: String` | developer widget definition String identifier matching `GlanceAdaptiveWidgetReceiver.widgetName`. |
| `widgetId: String?` | widget instance String identifier of the clicked widget instance (matching `androidx.glance.adaptive.core.WidgetInstanceInfo.widgetId`), or `null` if unknown. |
| `parameters: Bundle` | key-value arguments supplied to `GlanceAdaptiveAction.CallbackAction`. |