---
title: "runComposition"
description: "Returns a Flow<RemoteViews> that, on collection, starts a composition session for this
[GlanceAppWidget] and emits [RemoteViews] for each result. The composition is closed when the
flow is cancelled.

If a valid [id] is provided, this function will use the sizing values from the bound widget if
using [SizeMode.Exact] or [SizeMode.Single].

Lambda actions and list views in the emitted [RemoteViews] will continue to work while this is
flow is running. This currently does not support resizing (you have to run the flow again with
new [sizes]) or reloading the [androidx.glance.state.GlanceStateDefinition] state value.

Note: In order to handle lambda actions correctly, only one instance of runComposition for a
particular [id] may run at the same time. Calling runComposition concurrently with the same ID
will succeed, but the first call will resume with an exception.

If you need to call runComposition concurrently, you can omit [id] so that a random fake ID will
be used. Otherwise, call runComposition sequentially when using the same [id].

By default, this function uses [UnmanagedSessionReceiver] as the [lambdaReceiver] target to
receive any lambda actions while this function is running. If you need to run this function in a
non-default process, you can declare a sub-class of UnmanagedSessionReceiver in that process and
pass its [ComponentName] here."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-android'>Android</div>


```kotlin
@SuppressLint("PrimitiveInCollection")
@ExperimentalGlanceApi
public fun GlanceAppWidget.runComposition(
    @Suppress("ContextFirst") context: Context,
    id: GlanceId = createFakeAppWidgetId(),
    options: Bundle = Bundle(),
    sizes: List<DpSize>? = null,
    state: Any? = null,
    lambdaReceiver: ComponentName = ComponentName(context, UnmanagedSessionReceiver::class.java),
): Flow<RemoteViews>
```


Returns a Flow<RemoteViews> that, on collection, starts a composition session for this
`GlanceAppWidget` and emits `RemoteViews` for each result. The composition is closed when the
flow is cancelled.

If a valid `id` is provided, this function will use the sizing values from the bound widget if
using `SizeMode.Exact` or `SizeMode.Single`.

Lambda actions and list views in the emitted `RemoteViews` will continue to work while this is
flow is running. This currently does not support resizing (you have to run the flow again with
new `sizes`) or reloading the `androidx.glance.state.GlanceStateDefinition` state value.

Note: In order to handle lambda actions correctly, only one instance of runComposition for a
particular `id` may run at the same time. Calling runComposition concurrently with the same ID
will succeed, but the first call will resume with an exception.

If you need to call runComposition concurrently, you can omit `id` so that a random fake ID will
be used. Otherwise, call runComposition sequentially when using the same `id`.

By default, this function uses `UnmanagedSessionReceiver` as the `lambdaReceiver` target to
receive any lambda actions while this function is running. If you need to run this function in a
non-default process, you can declare a sub-class of UnmanagedSessionReceiver in that process and
pass its `ComponentName` here.



