Use https://wearables.developer.meta.com/docs/develop/dat/lifecycle-events/, then use the Wearables MCP endpoint https://mcp.developer.meta.com/wearables to call search_dat_docs for current DAT session lifecycle guidance. Inspect my session code first, then add the smallest lifecycle fix for STARTED, PAUSED, and STOPPED states, including interruption handling and resource cleanup. Avoid assuming transition reasons, keep UI state explicit, and run the relevant local checks.
DeviceSessionState is device-driven and delivered asynchronously. On Android, observe the state using state. On iOS, use stateStream().| State | Meaning | App expectation |
|---|---|---|
STOPPED | Session is inactive and not reconnecting. | Free resources. Wait for user action. |
STARTED | Session is active and streaming data. | Perform live work. |
PAUSED | Session is temporarily suspended. | Hold work. Paths may resume. |
DeviceSessionState does not expose the reason for a transition.DeviceSessionState and react without assuming the cause of a change.val session = Wearables.createSession(AutoDeviceSelector()).getOrThrow()
session.state.collect { state ->
when (state) {
DeviceSessionState.STARTED -> onStarted()
DeviceSessionState.PAUSED -> onPaused()
DeviceSessionState.STOPPED -> onStopped()
else -> {}
}
}
let session = try wearables.createSession(deviceSelector: AutoDeviceSelector(wearables: wearables))
for await state in session.stateStream() {
switch state {
case .started: onStarted()
case .paused: onPaused()
case .stopped: onStopped()
default: break
}
}
STARTED, confirm UI shows that the device session is live.PAUSED, keep the connection and wait for STARTED or STOPPED.STOPPED, release device resources and allow the user to restart.DeviceSessionState when:STOPPED, while some gestures pause a session and later resume it.DeviceSessionState changes to PAUSED:STARTED.Wearables.devicesMetadata[deviceId]?.collect { metadata ->
if (metadata.available) {
onDeviceAvailable()
} else {
onDeviceUnavailable()
}
}
let token = Wearables.shared.deviceForIdentifier(deviceId).addLinkStateListener { linkState in
if linkState == .connected {
onDeviceAvailable()
} else {
onDeviceUnavailable()
}
}
DeviceSessionState to STOPPED.session.state/stateStream and handle all DeviceSessionState values.STOPPED or loss of availability.