/mwdat-android:session-lifecyclefrom mwdat-android
Manages session and stream state for DAT SDK Android integrations, covering pause/resume behavior and device availability monitoring.
Ships in mwdat-android. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Manage session and stream state in DAT SDK integrations.
Create a DeviceSession with Wearables.createSession(...), start it, then attach capabilities such as camera streaming once the session is STARTED. Session lifecycle and capability lifecycle are related but distinct.
| State | Meaning | App action |
|---|---|---|
IDLE | Session created, not started yet | Call session.start() |
STARTING | Connecting to the device | Show loading UI |
STARTED | Session active and ready for capabilities | Add or use capabilities |
PAUSED | Session temporarily suspended by pause() or the device | Keep state, call session.resume() or wait for the device to resume |
STOPPING | Session is shutting down | Stop user work and wait |
STOPPED | Terminal; session ended | Release resources and create a new session if needed |
STOPPED is terminal: a stopped session cannot be restarted, so call Wearables.createSession(...) again for the next connection.
start(), stop(), pause(), and resume() are all sync fire-and-forget and return Unit. Subscribe to state and errors before calling start() so no transition is missed, and treat session.errors as the failure channel for start().
Wearables.createSession(AutoDeviceSelector()).fold(
onSuccess = { session ->
lifecycleScope.launch {
session.state.collect { state ->
when (state) {
DeviceSessionState.STARTED -> onStarted(session)
DeviceSessionState.PAUSED -> onPaused()
DeviceSessionState.STOPPED -> onStopped()
else -> Unit
}
}
}
lifecycleScope.launch {
session.errors.collect { error -> showError(error.description) }
}
session.start()
},
onFailure = { error, _ -> showError(error.description) },
)
Add each capability once from onStarted(session): a resumed session goes from PAUSED back to STARTED and keeps its capabilities, so a second session.addCamera(...) fails with DeviceSessionError.CAPABILITY_ALREADY_ADDED. Calling session.addCamera(...) while the session is still IDLE fails with DeviceSessionError.SESSION_IDLE, and calling it after STOPPED fails with DeviceSessionError.SESSION_ALREADY_STOPPED.
Camera streaming has its own state flow after you add a camera:
STOPPED -> STARTING -> STARTED -> STREAMING -> STOPPING -> STOPPED
CLOSED is the terminal stream state, and PAUSED is reported when the device pauses streaming (for example a single cap-touch tap) and can resume on its own.
lifecycleScope.launch {
camera.stream.state.collect { state ->
// React to stream state changes
}
}
The SDK may pause or stop a session when:
Call pause() on a STARTED session and resume() on a PAUSED one. Like start() and stop(), both are sync fire-and-forget: observe state for the STARTED -> PAUSED -> STARTED transitions. pause() outside STARTED and resume() outside PAUSED are no-ops. The state changes only when the device confirms, so wait for PAUSED before calling resume() (and for STARTED before calling pause() again); earlier calls are ignored. If the observed state doesn't match what your app wants, call pause() or resume() again once it settles.
pauseButton.setOnClickListener { session.pause() } // STARTED -> PAUSED
resumeButton.setOnClickListener { session.resume() } // PAUSED -> STARTED
The device can also pause and resume the session on its own (for example a single cap-touch tap). When a session is paused:
resume() or wait for the next observed session statelifecycleScope.launch {
Wearables.devices.collect { devices ->
// Update the list of available devices
}
}
Use Wearables.devices and device metadata to decide when it is sensible to create a new session after a stop.
DeviceSessionState values you care aboutDeviceSessionError and StreamError failuresWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
session-management, stream-state, android-sdk, device-session
npx claudepluginhub meta/meta-wearables-dat-android --plugin mwdat-android18 skills in this plugin
/dat-conventionsKotlin patterns, DatResult, session and capability conventions for DAT SDK Android developmentOther plugins' skills for the same job