SessionState is device-driven and delivered asynchronously. On Android, observe the state using getDeviceSessionState(). On iOS, use addDeviceSessionStateListener().| State | Meaning | App expectation |
|---|---|---|
STOPPED | Session is inactive and not reconnecting. | Free resources. Wait for user action. |
RUNNING | Session is active and streaming data. | Perform live work. |
PAUSED | Session is temporarily suspended. | Hold work. Paths may resume. |
SessionState does not expose the reason for a transition.SessionState and react without assuming the cause of a change.Wearables.getDeviceSessionState(deviceId).collect { state ->
when (state) {
SessionState.RUNNING -> onRunning()
SessionState.PAUSED -> onPaused()
SessionState.STOPPED -> onStopped()
}
}
let token = await Wearables.shared.addDeviceSessionStateListener(
forDeviceId: deviceId,
listener: { state in
switch state {
case .running: onRunning()
case .paused: onPaused()
case .stopped: onStopped()
default: break
}
}
)
RUNNING, confirm UI shows that the device session is live.PAUSED, keep the connection and wait for RUNNING or STOPPED.STOPPED, release device resources and allow the user to restart.SessionState when:STOPPED, while some gestures pause a session and later resume it.SessionState changes to PAUSED:RUNNING.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()
}
}
SessionState to STOPPED.getDeviceSessionState/addDeviceSessionStateListener and handle all SessionState values.STOPPED or loss of availability.