Delete data

Deleting data is a key part of Health Connect's CRUD operations. The examples below show you how to delete data by both Record UID or over a time range in a common workflow.

By Record unique identifier

The following code example shows how to delete step data by its UID. The Record unique identifier can be found in metadata.uid.

suspend fun deleteStepDataByUid(client: HealthConnectClient, uid: String) {
    client.deleteRecords(
        Steps::class,
        uidsList = listOf(uid),
        clientIdsList = emptyList()
    )
}

Over a time range

The following code example shows how to delete data of a specific data type in a time range.

suspend fun deleteDataByRange(client: HealthConnectClient) {
     client.deleteRecords(
          Steps::class,
          timeRangeFilter = TimeRangeFilter.between(START_TIME, END_TIME)
     )
}