Threading di WorkManager
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dalam artikel Mulai menggunakan WorkManager,
kami menyebutkan bahwa WorkManager melakukan pekerjaan latar belakang secara asinkron atas nama Anda. Penerapan dasar ini memenuhi permintaan sebagian besar aplikasi. Untuk kasus
penggunaan lanjutan lainnya, seperti menangani dengan benar pekerjaan yang dihentikan, Anda harus
mempelajari threading dan konkurensi di WorkManager.
Ada empat jenis elemen dasar pekerjaan yang disediakan WorkManager:
Worker
adalah penerapan yang paling sederhana,
dan sudah Anda lihat di bagian sebelumnya. WorkManager otomatis menjalankannya
pada thread latar belakang (yang bisa diganti). Baca selengkapnya tentang threading
di instance Worker
dalam Threading di Worker.
CoroutineWorker
merupakan
penerapan yang direkomendasikan bagi pengguna Kotlin. Instance CoroutineWorker
memperlihatkan fungsi penangguhan untuk pekerjaan latar belakang. Secara default, jenis ini
menjalankan Dispatcher
default, yang bisa Anda sesuaikan. Baca selengkapnya tentang threading di
instance CoroutineWorker
dalam Threading di CoroutineWorker.
RxWorker
adalah penerapan
yang direkomendasikan bagi pengguna RxJava. RxWorkers harus digunakan jika banyak kode
asinkron yang ada dicontohkan dalam RxJava. Seperti semua konsep RxJava,
Anda bebas memilih strategi threading pilihan Anda. Baca selengkapnya tentang
threading di instance RxWorker
dalam Threading di RxWorker.
ListenableWorker
adalah class
dasar untuk Worker
, CoroutineWorker
, dan RxWorker
. Hal ini ditujukan bagi
developer Java yang harus berinteraksi dengan API asinkron berbasis callback seperti FusedLocationProviderClient
dan tidak menggunakan RxJava. Baca selengkapnya
tentang threading di instance ListenableWorker
dalam Threading di ListenableWorker.
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-07-26 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-07-26 UTC."],[],[],null,["# Threading in WorkManager\n\nIn [Getting started with WorkManager](/topic/libraries/architecture/workmanager/basics),\nwe mentioned that WorkManager performs background work asynchronously on your\nbehalf. The basic implementation addresses the demands of most apps. For more\nadvanced use cases, such as correctly handling work being stopped, you should\nlearn about threading and concurrency in WorkManager.\n\nThere are four different types of work primitives provided by WorkManager:\n\n- [`Worker`](/reference/androidx/work/Worker) is the simplest implementation, and the one you have seen in previous sections. WorkManager automatically runs it on a background thread (that you can override). Read more about threading in `Worker` instances in [Threading in Worker](/topic/libraries/architecture/workmanager/advanced/worker).\n- [`CoroutineWorker`](/reference/kotlin/androidx/work/CoroutineWorker) is the recommended implementation for Kotlin users. `CoroutineWorker` instances expose a suspending function for background work. By default, they run a default `Dispatcher`, which you can customize. Read more about threading in `CoroutineWorker` instances in [Threading in CoroutineWorker](/topic/libraries/architecture/workmanager/advanced/coroutineworker).\n- [`RxWorker`](/reference/androidx/work/RxWorker) is the recommended implementation for RxJava users. RxWorkers should be used if a lot of your existing asynchronous code is modelled in RxJava. As with all RxJava concepts, you are free to choose the threading strategy of your choice. Read more about threading in `RxWorker` instances in [Threading in RxWorker](/topic/libraries/architecture/workmanager/advanced/rxworker).\n- [`ListenableWorker`](/reference/androidx/work/ListenableWorker) is the base class for `Worker`, `CoroutineWorker`, and `RxWorker`. It is intended for Java developers who have to interact with callback-based asynchronous APIs such as `FusedLocationProviderClient` and are not using RxJava. Read more about threading in `ListenableWorker` instances in [Threading in ListenableWorker](/topic/libraries/architecture/workmanager/advanced/listenableworker)."]]