# rememberPendingIntentAction

> Creates an [RemoteAction] that sends a [PendingIntent], filling in [extras] when the action runs.

## API Reference

### rememberPendingIntentAction

> Source set: Android

```kotlin
@Composable
public fun rememberPendingIntentAction(
    vararg extras: Pair<String, RemoteString>,
    pendingIntent: (Context) -> PendingIntent,
): RemoteAction
```

Creates an [RemoteAction](https://composables.com/jetpack-compose/androidx.compose.remote/remote-creation-compose/interfaces/RemoteAction/api.md) that sends a `PendingIntent`, filling in `extras` when the action runs.

The `PendingIntent` is not serialized into the document. It is stored in
`androidx.compose.remote.creation.compose.capture.RemoteCapturedDocument.pendingIntents`, keyed
by its index, and the host sends it when the action runs: the embedded player through
`PendingIntentActionHandler`, and `RemoteViews` hosts once it is registered with
`setOnClickPendingIntent(PendingIntentAction.FIRST_ACTION_ID + index, it)`.

`extras` are for values that are only known during playback, such as remote state. Each one is
added to the sent `android.content.Intent` as a `String` extra. Put constant values in the
`android.content.Intent` of the `PendingIntent` instead, where every host delivers them; constant
entries in `extras` are ignored. Extras are only delivered when:
- the `PendingIntent` is created with `PendingIntent.FLAG_MUTABLE`,
- the host fills them in, as `PendingIntentActionHandler` does, and
- the document is not captured for Wear widgets, whose hosts don't support them.

Otherwise the `PendingIntent` is sent without them, so receivers should handle a missing key.
Don't also put these keys in the `android.content.Intent`: filled in extras never replace extras
the `android.content.Intent` already has (see `android.content.Intent.fillIn`).

Example of remembering an action that triggers a `PendingIntent` when clicked:

#### Parameters

| | |
| --- | --- |
| extras | The `String` extras to fill in, as key to value pairs. |
| pendingIntent | A lambda that returns the `PendingIntent` to trigger. The [Context](https://developer.android.com/reference/android/content/Context) is provided to the lambda to ensure it's available during serialization. |

#### Return

a remembered [RemoteAction](https://composables.com/jetpack-compose/androidx.compose.remote/remote-creation-compose/interfaces/RemoteAction/api.md) that sends the `PendingIntent`

## Code Examples

### PendingIntentActionSample

```kotlin
@Sampled
@Preview
@PreviewWrapper(RemoteComponentPreviewWrapper::class)
@Composable
fun PendingIntentActionSample() {
    val launchAction = rememberPendingIntentAction { context ->
        val intent = Intent(Intent.ACTION_MAIN).setPackage(context.packageName)
        PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
    }

    RemoteBox(
        modifier =
            RemoteModifier.clip(RemoteRoundedCornerShape(12.rdp))
                .background(Color(0xFF1E88E5).rc)
                .clickable(launchAction)
                .padding(16.rdp),
        contentAlignment = RemoteAlignment.Center,
    ) {
        RemoteText(text = "Open App".rs, color = Color.White.rc)
    }
}
```
