Delete data

Stay organized with collections Save and categorize content based on your preferences.

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 deleteStepsByUniqueIdentifier(
    healthConnectClient: HealthConnectClient,
    uid1: String,
    uid2: String
) {
    healthConnectClient.deleteRecords(
        StepsRecord::class,
        uidsList = listOf(uid1, uid2),
        clientRecordIdsList = 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 deleteStepsByTimeRange(
    healthConnectClient: HealthConnectClient,
    startTime: Instant,
    endTime: Instant
) {
    healthConnectClient.deleteRecords(
        StepsRecord::class,
        timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
    )
}