קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אחרי שמירת הגדרת הגדרה, צריך להוסיף לאפליקציה קריאה חוזרת (callback) כדי להגיב כשהיא מופעלת. אפשר לעשות זאת באמצעות שימוש במחלקת משנה של BroadcastReceiver כדי לטפל בשיטות Intent מגדרות.
לפני שמוסיפים קריאות חזרה למחסום, צריך קודם לרשום את המחסום.
יצירת תת-סוג של BroadcastReceiver
בדוגמה הבאה מוצגת המחלקה FenceReceiver, שמרחיבה את BroadcastReceiver. הכיתה מיישמת את שיטת הקריאה החוזרת BroadcastReceiver.onReceive() כדי לטפל בכל השיטות מסוג Intent שמקורן במחסומים שנוצרו על ידי האפליקציה. כשמתקבלת הודעה מסוג Intent, השיטה FenceState.extract() משמשת לקבלת מצב המחסום ולהעברתו לקריאה החוזרת.
[[["התוכן קל להבנה","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-08-08 (שעון UTC)."],[[["After registering a fence, your app needs to add a callback to respond when the fence is triggered."],["Callbacks for fences are implemented using a subclass of `BroadcastReceiver` to manage `Intent` methods."],["The `BroadcastReceiver.onReceive()` method within the subclass handles `Intent` methods from the fences your app has created."],["The `FenceState.extract()` method is used to retrieve the fence state from a received `Intent` and provide it to the callback."]]],["After registering a fence, a callback must be added to respond when it's triggered. This is achieved by creating a subclass of `BroadcastReceiver`. The `FenceReceiver` class, extending `BroadcastReceiver`, implements the `onReceive()` method. Upon receiving an `Intent` from a fence, `FenceState.extract()` retrieves the fence state. The code then checks the fence key and current state (`TRUE`, `FALSE`, or `UNKNOWN`) to update the log view. This allows the app to react to fence state changes.\n"]]