ลบข้อมูล
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การลบข้อมูลเป็นส่วนสำคัญของการดำเนินการ CRUD ใน Health Connect คู่มือนี้
จะแสดงวิธีการลบระเบียนใน 2 วิธี
ลบโดยใช้รหัสระเบียน
คุณสามารถลบระเบียนโดยใช้รายการตัวระบุที่ไม่ซ้ำกัน เช่น รหัสระเบียน
และรหัสระเบียนไคลเอ็นต์ของแอป ใช้ deleteRecords
และ
ให้รายการ Strings
2 รายการ รายการหนึ่งสำหรับรหัสระเบียน และอีกรายการหนึ่งสำหรับ
Client-ID หากมีรหัสที่ใช้ได้เพียงรหัสเดียว ให้ตั้งค่า emptyList()
ในรายการอื่น
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีลบข้อมูลขั้นตอนโดยใช้รหัส
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
}
}
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-08-23 UTC
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"ไม่มีข้อมูลที่ฉันต้องการ"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"ล้าสมัย"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"ปัญหาเกี่ยวกับการแปล"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"อื่นๆ"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"เข้าใจง่าย"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"แก้ปัญหาของฉันได้"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"อื่นๆ"
}]
{"lastModified": "\u0e2d\u0e31\u0e1b\u0e40\u0e14\u0e15\u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14 2024-08-23 UTC"}
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2024-08-23 UTC"]]