Disconnect
b.well Health SDK for Android
Disconnecting an On-Device Health Source
Overview
The disconnect method in the b.well SDK ends an on-device health sync session and removes the underlying connection. Call this before switching which user or on-device health source is connected on a device.
disconnect is called on BWellSdk.healthSync — BWellSdk.healthSync.disconnect() — the same object every other Health Sync method (connect, requestPermissions, sync) lives on.
This is not the same as disconnecting a Cloud Provider. This method only tears down an on-device sync session (e.g. the Android Health Connect session). To remove a Cloud Provider connection (e.g. a fitness platform's OAuth account), use Delete a Connection (
deleteConnection) instead — the two are unrelated calls.
Method Signature
suspend fun disconnect(sourceId: String? = null): BWellResult<Unit>sourceId: identifies which registered on-device source to disconnect. In practice, omit this — callBWellSdk.healthSync.disconnect()with no arguments, same reasoning asconnect: there's currently only one supported adapter, auto-selected.BWellResult<Unit>: Indicates whether the session and connection were removed successfully.
Under the Hood
disconnect runs 2 steps, and both always run regardless of whether the first one fails:
- Ends the on-device sync session (the adapter's own session teardown).
- Deletes the backend connection record (
deleteConnection).
If both fail, the session-teardown failure is reported — a lingering on-device session is treated as the more serious problem than a lingering backend connection record.
Example Usage
val disconnectResult = BWellSdk.healthSync.disconnect()
if (!disconnectResult.success()) {
// Inspect disconnectResult.error for details
}Best Practices
- Call
disconnectbeforeconnect-ing a different user or source on the same device to avoid a session conflict. - Call
disconnecton user logout to ensure no on-device session persists across accounts.
Updated 12 days ago
