UnmanagedSessionReceiver
open class UnmanagedSessionReceiver : BroadcastReceiver()
This receiver responds to lambda action clicks for unmanaged sessions (created by
GlanceAppWidget.runComposition
). In managed sessions that compose UI for a bound widget, the
widget's GlanceAppWidgetReceiver
is used as the receiver for lambda actions. However, when
running a session with GlanceAppWidget.runComposition
, there is no guarantee that the widget is
attached to some GlanceAppWidgetReceiver. Instead, unmanaged sessions register themselves to
receive lambdas while they are running (with UnmanagedSessionReceiver.registerSession
), and set
their lambda target to UnmanagedSessionReceiver
. This is also used by
GlanceRemoteViewsService
to provide list items for unmanaged sessions.
Companion Object
Methods
suspend fun registerSession(appWidgetId: Int, session: AppWidgetSession): Nothing
Registers session
to handle lambdas created from an unmanaged session running for
appWidgetId
.
This call will suspend once the session is registered. On cancellation, this session will be unregistered. That way, the registration is tied to the surrounding coroutine scope and does not need to be manually unregistered.
If called from another coroutine with the same appWidgetId
, this call will resume with
an exception, and the new registration will succeed. (i.e., only one session per
appWidgetId
can be registered at the same time). By default, runComposition
uses
random fake IDs, so this could only happen if the user calls runComposition
with two
identical real IDs.
fun getSession(appWidgetId: Int): AppWidgetSession?