데이터 삭제
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
데이터 삭제는 헬스 커넥트의 CRUD 작업의 핵심 부분입니다. 이 가이드에서는 레코드를 삭제하는 두 가지 방법을 보여줍니다.
레코드 ID를 사용하여 삭제
레코드 ID 및 앱의 클라이언트 레코드 ID와 같은 고유 식별자 목록을 사용하여 레코드를 삭제할 수 있습니다. deleteRecords
를 사용한 다음, 이를 두 개의 Strings
목록(레코드 ID에 대한 목록과 클라이언트 ID에 대한 목록)에 제공합니다. ID 중 하나만 사용 가능한 경우 다른 목록에서 emptyList()
를 설정할 수 있습니다.
다음 코드 예에서는 ID를 사용하여 걸음 수 데이터를 삭제하는 방법을 보여줍니다.
suspend fun deleteStepsByUniqueIdentifier(
healthConnectClient: HealthConnectClient,
idList: List<String>
) {
try {
healthConnectClient.deleteRecords(
StepsRecord::class,
idList = idList,
clientRecordIdsList = emptyList()
)
} catch (e: Exception) {
// Run error handling here
}
}
기간을 사용하여 삭제
기간을 필터로 사용하여 데이터를 삭제할 수도 있습니다.
deleteRecords
를 사용한 다음, 이를 시작 및 종료 타임스탬프 값을 갖는 TimeRangeFilter
객체에 제공합니다.
다음 코드 예에서는 특정 시간의 걸음 수 데이터를 삭제하는 방법을 보여줍니다.
suspend fun deleteStepsByTimeRange(
healthConnectClient: HealthConnectClient,
startTime: Instant,
endTime: Instant
) {
try {
healthConnectClient.deleteRecords(
StepsRecord::class,
timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
)
} catch (e: Exception) {
// Run error handling here
}
}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Delete data\n\nDeleting data is a key part of the CRUD operations in Health Connect. This guide\nshows you how you can delete records in two ways.\n| **Tip:** For further guidance on deleting data, take a look at the [Android Developer video for reading and writing data](https://www.youtube.com/watch?v=NAx7Gv_Hk7E&t=299) in Health Connect.\n\nDelete using Record IDs\n-----------------------\n\nYou can delete records using a list of unique identifiers such as the Record ID\nand your app's Client Record ID. Use [`deleteRecords`](/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,kotlin.collections.List,kotlin.collections.List)), and\nsupply it with two lists of `Strings`, one for the Record IDs and one for the\nClient IDs. If you only have one of the IDs available, you can set `emptyList()`\non the other list.\n\nThe following code example shows how to delete Steps data using its IDs: \n\n suspend fun deleteStepsByUniqueIdentifier(\n healthConnectClient: HealthConnectClient,\n idList: List\u003cString\u003e\n ) {\n try {\n healthConnectClient.deleteRecords(\n StepsRecord::class,\n idList = idList,\n clientRecordIdsList = emptyList()\n )\n } catch (e: Exception) {\n // Run error handling here\n }\n }\n\nDelete using a time range\n-------------------------\n\nYou can also delete data using a time range as your filter.\nUse [`deleteRecords`](/reference/kotlin/androidx/health/connect/client/HealthConnectClient#deleteRecords(kotlin.reflect.KClass,androidx.health.connect.client.time.TimeRangeFilter)), and supply it with a\n[`TimeRangeFilter`](/reference/kotlin/androidx/health/connect/client/time/TimeRangeFilter) object that takes\na start and end timestamp values.\n\nThe following code example shows how to delete data of Steps data on a\nspecific time: \n\n suspend fun deleteStepsByTimeRange(\n healthConnectClient: HealthConnectClient,\n startTime: Instant,\n endTime: Instant\n ) {\n try {\n healthConnectClient.deleteRecords(\n StepsRecord::class,\n timeRangeFilter = TimeRangeFilter.between(startTime, endTime)\n )\n } catch (e: Exception) {\n // Run error handling here\n }\n }"]]