WorkManager は、永続処理のための推奨ソリューションです。アプリの再起動やシステムの再起動後もスケジュール設定が維持された場合、処理は永続します。ほとんどのバックグラウンド処理は永続処理で実現することが最善であるため、WorkManager が、バックグラウンド処理に推奨される主要な API です。
[[["わかりやすい","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-07-30 UTC。"],[],[],null,["# App Architecture: Data Layer - Schedule Task with WorkManager - Android Developers\n\nSchedule tasks with WorkManager\nPart of [Android Jetpack](/jetpack).\n====================================================================\n\n[WorkManager](/reference/androidx/work/WorkManager) is the recommended solution for persistent work. Work is\npersistent when it remains scheduled through app restarts and system reboots.\nBecause most background processing is best accomplished through persistent work,\nWorkManager is the primary recommended API for background processing.\n\nTypes of persistent work\n------------------------\n\nWorkManager handles three types of persistent work:\n\n- **Immediate**: Tasks that must begin immediately and complete soon. May be expedited.\n- **Long Running**: Tasks which might run for longer, potentially longer than 10 minutes.\n- **Deferrable**: Scheduled tasks that start at a later time and can run periodically.\n\nFigure 1 outlines how the different types of persistent work relate to one\nanother.\n**Figure 1**: Types of persistent work.\n\nSimilarly, the following table outlines the various types of work.\n\n| **Type** | **Periodicity** | **How to access** |\n| Immediate | One time | `OneTimeWorkRequest` and `Worker`. For expedited work, call `setExpedited()` on your OneTimeWorkRequest. |\n| Long Running | One time or periodic | Any `WorkRequest` or `Worker`. Call `setForeground()` in the Worker to handle the notification. |\n| Deferrable | One time or periodic | `PeriodicWorkRequest` and `Worker`. |\n|--------------|----------------------|----------------------------------------------------------------------------------------------------------|\n\nFor more information regarding how to set up WorkManager, see the [Defining your\nWorkRequests](/topic/libraries/architecture/workmanager/how-to/define-work#work-constraints) guide.\n\nFeatures\n--------\n\nIn addition to providing a simpler and more consistent API, WorkManager has a\nnumber of other key benefits:\n\n### Work constraints\n\nDeclaratively define the optimal conditions for your work to run using [work\nconstraints](/topic/libraries/architecture/workmanager/how-to/define-work#work-constraints). For example, run only when the device is on an unmetered\nnetwork, when the device is idle, or when it has sufficient battery.\n\n### Robust scheduling\n\nWorkManager allows you to [schedule work](/topic/libraries/architecture/workmanager/how-to/define-work) to run [one-time](/reference/androidx/work/OneTimeWorkRequest) or\n[repeatedly](/reference/androidx/work/PeriodicWorkRequest) using flexible scheduling windows. Work can be tagged and named\nas well, allowing you to schedule unique, replaceable work and monitor or cancel\ngroups of work together.\n\nScheduled work is stored in an internally managed SQLite database and\nWorkManager takes care of ensuring that this work persists and is rescheduled\nacross device reboots.\n\nIn addition, WorkManager adheres to power-saving features and best practices\nlike [Doze mode](/training/monitoring-device-state/doze-standby), so you don't have to worry about it.\n\n### Expedited work\n\nYou can use WorkManager to schedule immediate work for execution in the\nbackground. You should use [Expedited work](/topic/libraries/architecture/workmanager/how-to/define-work#expedited) for tasks that are important to\nthe user and which complete within a few minutes.\n\n### Flexible retry policy\n\nSometimes work fails. WorkManager offers [flexible retry policies](/topic/libraries/architecture/workmanager/how-to/define-work#retries_backoff), including\na configurable [exponential backoff policy](/reference/androidx/work/BackoffPolicy).\n\n### Work chaining\n\nFor complex related work, [chain individual work tasks together](/topic/libraries/architecture/workmanager/how-to/chain-work) using an\nintuitive interface that allows you to control which pieces run sequentially and\nwhich run in parallel. \n\n### Kotlin\n\n```kotlin\nval continuation = WorkManager.getInstance(context)\n .beginUniqueWork(\n Constants.IMAGE_MANIPULATION_WORK_NAME,\n ExistingWorkPolicy.REPLACE,\n OneTimeWorkRequest.from(CleanupWorker::class.java)\n ).then(OneTimeWorkRequest.from(WaterColorFilterWorker::class.java))\n .then(OneTimeWorkRequest.from(GrayScaleFilterWorker::class.java))\n .then(OneTimeWorkRequest.from(BlurEffectFilterWorker::class.java))\n .then(\n if (save) {\n workRequest\u003cSaveImageToGalleryWorker\u003e(tag = Constants.TAG_OUTPUT)\n } else /* upload */ {\n workRequest\u003cUploadWorker\u003e(tag = Constants.TAG_OUTPUT)\n }\n )\n```\n\n### Java\n\n```java\nWorkManager.getInstance(...)\n.beginWith(Arrays.asList(workA, workB))\n.then(workC)\n.enqueue();\n```\n\nFor each work task, you can [define input and output data](/topic/libraries/architecture/workmanager/how-to/define-work#input_output) for that work.\nWhen chaining work together, WorkManager automatically passes output data from\none work task to the next.\n\n### Built-In threading interoperability\n\nWorkManager [integrates seamlessly](/topic/libraries/architecture/workmanager/advanced/threading) with [Coroutines](/topic/libraries/architecture/workmanager/advanced/coroutineworker) and [RxJava](/topic/libraries/architecture/workmanager/advanced/rxworker)\nand provides the flexibility to [plug in your own asynchronous APIs](/topic/libraries/architecture/workmanager/advanced/listenableworker).\n| **Note:** While Coroutines and WorkManager are recommended for different use cases, they are not mutually exclusive. You may use coroutines within work scheduled through WorkManager.\n\nUse WorkManager for reliable work\n---------------------------------\n\nWorkManager is intended for work that is required to **run reliably** even if\nthe user navigates off a screen, the app exits, or the device restarts. For\nexample:\n\n- Sending logs or analytics to backend services.\n- Periodically syncing application data with a server.\n\nWorkManager is not intended for in-process background work that can safely be\nterminated if the app process goes away. It is also not a general solution for\nall work that requires immediate execution. Please review the [background\nprocessing guide](/guide/background) to see which solution meets your needs.\n\nRelationship to other APIs\n--------------------------\n\nWhile coroutines are the recommended solution for certain use cases, you should\nnot use them for persistent work. It is important to note that coroutines is a\nconcurrency framework, whereas WorkManager is a library for persistent work.\nLikewise, you should use AlarmManager for clocks or calendars only.\n\n| **API** | **Recommended for** | **Relationship to WorkManager** |\n|------------------|-----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Coroutines** | All asynchronous work that doesn't need to be persistent. | Coroutines are the standard means of leaving the main thread in Kotlin. However, they leave memory once the app closes. For persistent work, use WorkManager. |\n| **AlarmManager** | Alarms only. | Unlike WorkManager, AlarmManager wakes a device from Doze mode. It is therefore not efficient in terms of power and resource management. Only use it for precise alarms or notifications such as calendar events --- not background work. |\n\nReplacing deprecated APIs\n-------------------------\n\nThe WorkManager API is the recommended replacement for previous Android\nbackground scheduling APIs, including [`FirebaseJobDispatcher`](/topic/libraries/architecture/workmanager/migrating-fb) and\n[`GcmNetworkManager`](/topic/libraries/architecture/workmanager/migrating-gcm).\n| **Note:** If your app targets Android 10 (API level 29) or above, your `FirebaseJobDispatcher` and `GcmNetworkManager` API calls will no longer work on devices running Android Marshmallow (6.0) and above. Follow the migration guides for [`FirebaseJobDispatcher`](/topic/libraries/architecture/workmanager/migrating-fb) and [`GcmNetworkManager`](/topic/libraries/architecture/workmanager/migrating-gcm) for guidance on migrating.\n\nGetting started\n---------------\n\nCheck out the [Getting started guide](/topic/libraries/architecture/workmanager/basics) to start using WorkManager in your\napp.\n\n### Additional resources\n\nFor further information about `WorkManager`, consult the following\nresources.\n\n#### Samples\n\n#### Videos\n\n- [Workmanager - MAD Skills](https://www.youtube.com/playlist?list=PLWz5rJ2EKKc_J88-h0PhCO_aV0HIAs9Qk), video series\n- [Working with WorkManager](https://www.youtube.com/watch?v=83a4rYXsDs0), from the 2018 Android Dev Summit\n- [WorkManager: Beyond the basics](https://www.youtube.com/watch?v=Bz0z694SrEE), from the 2019 Android Dev Summit\n\n#### Blogs\n\n- [Introducing WorkManager](https://medium.com/androiddevelopers/introducing-workmanager-2083bcfc4712)\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [App Startup](/topic/libraries/app-startup)"]]