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.healthSyncBWellSdk.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 — call BWellSdk.healthSync.disconnect() with no arguments, same reasoning as connect: 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:

  1. Ends the on-device sync session (the adapter's own session teardown).
  2. 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 disconnect before connect-ing a different user or source on the same device to avoid a session conflict.
  • Call disconnect on user logout to ensure no on-device session persists across accounts.

Did this page help you?