Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sau khi đăng ký một hàng rào, ứng dụng của bạn phải thêm một lệnh gọi lại để phản hồi khi hàng rào được kích hoạt. Bạn có thể thực hiện việc này bằng cách sử dụng một lớp con của BroadcastReceiver để xử lý các phương thức Intent từ hàng rào.
Trước khi thêm lệnh gọi lại vào một hàng rào, trước tiên, bạn phải đăng ký hàng rào đó.
Tạo một lớp con của BroadcastReceiver
Ví dụ sau đây cho thấy lớp FenceReceiver mở rộng BroadcastReceiver. Lớp này triển khai phương thức gọi lại BroadcastReceiver.onReceive() để xử lý tất cả phương thức Intent bắt nguồn từ hàng rào do ứng dụng của bạn tạo. Khi nhận được Intent, phương thức FenceState.extract() sẽ được dùng để lấy trạng thái hàng rào và chuyển trạng thái đó đến lệnh gọi lại.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-06-24 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"]]