מחיקת נתונים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מחיקת נתונים היא חלק מרכזי בפעולות ה-CRUD ב-Health Connect. המדריך הזה
מראה איך למחוק רשומות בשתי דרכים.
מחיקה באמצעות מזהי רשומות
אפשר למחוק רשומות באמצעות רשימה של מזהים ייחודיים, כמו מזהה הרשומה
ומזהה הלקוח של האפליקציה שלכם. משתמשים ב-deleteRecords
.
צריך לספק לו שתי רשימות של Strings
, אחת למזהי הרשומות ואחת ל
מזהי לקוח. אם יש לך רק אחד מהמזהים הזמינים, אפשר להגדיר את 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 ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון 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"]],["עדכון אחרון: 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 }"]]