Function

hostAction

Creates a RemoteAction that triggers a named action on the host.

hostAction

Source set: JvmAndAndroid
public fun hostAction(name: RemoteString): RemoteAction

Creates a RemoteAction that triggers a named action on the host.

Named actions are delivered to the onNamedAction callback of the Compose players. name may be a constant or a dynamic RemoteString; a dynamic name is resolved to its current value when the action runs.

Launcher widgets (RemoteViews) only dispatch id actions; use hostAction with an id there.

Example of dispatching a named action to the host when clicked:

Parameters

name The name of the action.

Return

a RemoteAction that triggers the named name action on the host

hostAction

Source set: JvmAndAndroid
public fun hostAction(name: RemoteString, value: RemoteFloat): RemoteAction

Creates a RemoteAction that triggers a named action on the host with a float value.

Parameters

name The name of the action.
value The float value to pass with the action, delivered to the host as a Float.

Return

a RemoteAction that triggers the named name action with value on the host

hostAction

Source set: JvmAndAndroid
public fun hostAction(name: RemoteString, value: RemoteInt): RemoteAction

Creates a RemoteAction that triggers a named action on the host with an int value.

Parameters

name The name of the action.
value The int value to pass with the action, delivered to the host as an Int.

Return

a RemoteAction that triggers the named name action with value on the host

hostAction

Source set: JvmAndAndroid
public fun hostAction(name: RemoteString, value: RemoteString): RemoteAction

Creates a RemoteAction that triggers a named action on the host with a string value.

Parameters

name The name of the action.
value The string value to pass with the action, delivered to the host as a String.

Return

a RemoteAction that triggers the named name action with value on the host

hostAction

Source set: JvmAndAndroid
public fun hostAction(name: RemoteString, value: RemoteBoolean): RemoteAction

Creates a RemoteAction that triggers a named action on the host with a boolean value.

The document format has no boolean payload, so the value is delivered to the host as an Int: 1 for true and 0 for false.

Parameters

name The name of the action.
value The boolean value to pass with the action.

Return

a RemoteAction that triggers the named name action with value on the host

hostAction

Source set: JvmAndAndroid
public fun hostAction(id: Int, metadata: RemoteString? = null): RemoteAction

Creates a RemoteAction that triggers an id action on the host, with optional string metadata.

Id actions are delivered to the onAction callback of the Compose players, and are the only host actions that platform RemoteViews hosts (launcher widgets, notifications) dispatch: a click runs the PendingIntent registered with RemoteViews.setOnClickPendingIntent(id, ...).

id is written into the document as a literal, so it is stable across captures and can be used as a key on the host. Choose ids that do not collide with explicit component ids in the same document, because players also treat an id action as a programmatic click on a component with that id.

To pass several values, combine them into metadata with RemoteString concatenation, for example "x=".rs + x.toRemoteString() + "&y=".rs + y.toRemoteString(), and decode them on the host.

Parameters

id The id of the action.
metadata Optional metadata delivered with the action. May be dynamic, for example built from touch positions or other remote state, and is resolved when the action runs.

Return

a RemoteAction that triggers the host action for id

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: