Usage

Usage

Start

val now = Clock.System.now().toEpochMilliseconds()
val content =
    LiveActivityContent(
        title = "Focus session",
        subtitle = "Deep work",
        progress = LiveActivityProgress.Determinate(current = 0, max = 25),
        timer = LiveActivityTimer(startAtEpochMillis = now, endAtEpochMillis = now + 25 * 60_000L),
        icon = "timer",                 // SF Symbol on iOS; key for iconResolver on Android
        accentColorArgb = 0xFF4F46E5,
    )
 
val result = liveActivities.start(LiveActivityRequest(content, deepLink = "myapp://focus"))

Update

liveActivities.update(id, content.copy(timer = content.timer?.copy(pausedAtEpochMillis = now)))

Only send an update when the content changes. The timer ticks on its own.

End

liveActivities.end(id, finalContent = content.copy(title = "Session complete"))      // Default dismissal
liveActivities.end(id)                                                                // removed now
liveActivities.end(id, finalContent, LiveActivityDismissal.After(now + 60_000L))

Observe

val activities by liveActivities.activities.collectAsState()

Each LiveActivity carries its last content and a state: Active, Ended, Dismissed, or Expired when the system ended it (iOS stops activities after eight hours).

Content fields

FieldiOSAndroid
title, subtitleLock Screen + expanded islandNotification title + text
shortTextCompact trailing slot (replaces the timer there)Status-bar chip (replaces the timer there)
progressProgress barProgressStyle
timerText(timerInterval:)Chronometer
iconSF Symbol nameiconResolver(key)
accentColorArgbTintsetColor
staleAtEpochMillisstaleDateignored
valuesAvailable to a custom widgetStored in extras

Encoded requests must stay under 3 KB (PayloadTooLarge otherwise).