Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
TileService adalah layanan terikat. TileService Anda terikat karena permintaan aplikasi atau jika sistem perlu berkomunikasi dengannya. Siklus proses layanan terikat
biasanya berisi empat metode callback berikut:
onCreate(), onBind(), onUnbind(), dan onDestroy().
Sistem memanggil metode ini setiap kali layanan memasuki fase siklus proses
baru.
Namun, TileService berbeda dari sebagian besar layanan terikat lainnya karena juga
berisi metode siklus proses yang spesifik untuk TileService. Metode siklus proses
Service dan metode siklus proses TileService dipanggil dalam dua thread asinkron
terpisah.
Lihat dokumentasi TileService untuk informasi selengkapnya tentang metode dan peristiwa ini.
Membuat kueri kartu yang aktif
Kartu aktif adalah kartu yang telah ditambahkan untuk ditampilkan di smartwatch. Gunakan
metode statis TileService, yaitu getActiveTilesAsync() untuk membuat kueri kartu
milik aplikasi Anda yang aktif.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-08-09 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-09 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."]]