Composable Function

rememberPendingIntentAction

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

rememberPendingIntentAction

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

Creates an RemoteAction 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 is provided to the lambda to ensure it's available during serialization.

Return

a remembered RemoteAction that sends the PendingIntent

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: