public final class LiveActivity
- Object
- LiveActivity
A running live activity: an ongoing-state surface (delivery, timer, ride, score) presented on the iOS lock screen and Dynamic Island, as an ongoing Android notification, or as a floating pill window on desktop. Start it with a descriptor and an initial state, then push fresh state maps as the situation evolves – updates ship only the state, the layout is re-interpolated on the surface:
LiveActivity delivery = LiveActivity.start(descriptor, initialState);
...
delivery.update(stateMap("Arriving now", eta, 1.0f));
delivery.end(null);
On platforms without live activity support start(...) returns an inert handle whose methods
are safe no-ops (isActive() returns false), so app code needs no platform checks.
Methods
Inherited methods
Method details
isSupported
public static boolean isSupported()start(LiveActivityDescriptor, Map)). It turns false once the user has refused that
prompt as often as start will raise it, or has switched notifications off for the app.Returns
start
public static LiveActivity start(LiveActivityDescriptor descriptor, Map<String, Object> initialState)Starts a live activity. On unsupported platforms (or when the platform refuses, e.g. the user disabled live activities) this returns an inert handle rather than throwing.
On Android 13 and newer the ongoing notification a live activity lowers to needs the
POST_NOTIFICATIONS permission, so the first start on a fresh install raises the system
prompt and blocks until the user answers. Start that first activity with your app in the
foreground: a background service or push handler has no UI to prompt from and the start is
refused. The prompt is raised at most twice across an install, after which isSupported()
reports false.
Threading
Callable from any thread, and a background thread is the right one. Starting an activity
serializes the descriptor, writes its PNG blobs where the platform renderer can reach them
and makes a synchronous native request (Activity.request is an XPC round trip on iOS).
The simulator makes all of that free, so an app that starts activities on the EDT looks
fine there and stalls on hardware; Surfaces.setDiagnosticsEnabled(Boolean) describes the
checks that catch it. Note also that the returned handle is the only way to update or end
this activity: check isActive() rather than tracking a flag of your own, or a start that
the platform refused leaves you starting a second activity on top of a live one.
Parameters
descriptorLiveActivityDescriptor- the activity layout and regions
initialStateMap<String, Object>- the initial state map, may be null
Returns
isActive() to know whether it is liveupdateRemote
public static void updateRemote(String id, String stateJson)endRemote
public static void endRemote(String id, String finalStateJson, boolean dismissImmediately)finalStateJson may be null to keep the last published state, matching the
SurfaceBridge contract.update
public void update(Map<String, Object> state)Parameters
stateMap<String, Object>- the new state map
end
public void end(Map<String, Object> finalState)Parameters
finalStateMap<String, Object>- the final state to show, or null to keep the last state
end
public void end(Map<String, Object> finalState, boolean dismissImmediately)Parameters
finalStateMap<String, Object>- the final state to show, or null to keep the last state
dismissImmediatelyboolean- true to remove the surface right away instead of letting the platform linger on the final state
isActive
public boolean isActive()end).getId
public String getId()