Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
TileService to powiązana usługa. Twoje TileService jest powiązane w wyniku żądania aplikacji lub jeśli system musi się z nią komunikować. Typowy cykl życia usługi związanej zawiera 4 metody wywołania zwrotnego: onCreate(), onBind(), onUnbind() i onDestroy().
System wywołuje te metody za każdym razem, gdy usługa wchodzi w nowy etap cyklu życia.
Usługa TileService różni się jednak od większości innych usług powiązanych, ponieważ zawiera też metody cyklu życia dotyczące konkretnej usługi TileService. Metody cyklu życia Service i metody cyklu życia TileService są wywoływane w 2 oddzielnych wątkach asynchronicznych.
Więcej informacji o tych metodach i zdarzeniach znajdziesz w dokumentacji TileService.
Zapytanie o to, które kafelki są aktywne
Aktywne karty to karty, które zostały dodane do wyświetlania na zegarku. Użyj statycznej metody TileServicegetActiveTilesAsync(), aby zapytać, które kafelki Twojej aplikacji są aktywne.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-07-27 UTC."],[],[],null,["# Lifecycle and analytics events\n\n`TileService` is a [bound service](/guide/components/bound-services). Your `TileService` is bound as a result\nof your app request or if the system needs to communicate with it. A typical\n[bound-service lifecycle](/guide/components/bound-services#Lifecycle) contains the following four callback methods:\n[`onCreate()`](/reference/android/app/Service#onCreate()), [`onBind()`](/reference/android/app/Service#onBind(android.content.Intent)), [`onUnbind()`](/reference/android/app/Service#onUnbind(android.content.Intent)), and [`onDestroy()`](/reference/android/app/Service#onDestroy()).\nThe system invokes these methods each time the service enters a new lifecycle\nphase.\n\nHowever, `TileService` differs from most other bound services because it also\ncontains `TileService`-specific lifecycle methods. The `Service` lifecycle\nmethods and the `TileService` lifecycle methods are called in two separate\nasynchronous threads.\n\nThere are two categories of `TileService` methods:\n\n- **Methods relating to core Tile functionality.** [`onTileRequest()`](/reference/androidx/wear/tiles/TileService#onTileRequest(androidx.wear.tiles.RequestBuilders.TileRequest)) (mandatory to implement) and [`onTileResourcesRequest()`](/reference/androidx/wear/tiles/TileService#onTileResourcesRequest(androidx.wear.tiles.RequestBuilders.ResourcesRequest)) are in this category.\n- **Methods relating to analytics and visibility.** This includes methods such as:\n - [`onTileAddEvent()`](/reference/androidx/wear/tiles/TileService#onTileAddEvent(androidx.wear.tiles.EventBuilders.TileAddEvent)) called when when the user adds your tile to the carousel\n - [`onTileRemoveEvent()`](/reference/androidx/wear/tiles/TileService#onTileRemoveEvent(androidx.wear.tiles.EventBuilders.TileRemoveEvent)) called when the user removes your tile from the carousel\n - [`onRecentInteractionEventsAsync()`](/reference/androidx/wear/tiles/TileService#onRecentInteractionEventsAsync(java.util.List%3Candroidx.wear.tiles.EventBuilders.TileInteractionEvent%3E)) provides information about recent user and system interactions with tiles\n\nSee the [`TileService`](/reference/androidx/wear/tiles/TileService) documentation for more information about these\nmethods and events.\n\n### Query which tiles are active\n\n*Active tiles* are tiles which have been added for display on the watch. Use\n`TileService`'s static method [`getActiveTilesAsync()`](/reference/androidx/wear/tiles/TileService#getActiveTilesAsync(android.content.Context,java.util.concurrent.Executor)) to query which tiles\n*belonging to your app* are active.\n| **Caution:** The result reflects the list of active tiles at the time the call was made, which might have changed by the time the result is received. Use `onTileAddEvent()` and `onTileRemoveEvent()` callbacks for scheduling actions that need to happen when your tile becomes either active or inactive."]]