[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"没有我需要的信息"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"太复杂/步骤太多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"内容需要更新"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/代码问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
WorkManager 中的线程处理
在 WorkManager 使用入门中,我们提到 WorkManager 可以代表您异步执行后台工作。该基本实现可满足大多数应用的需求。关于更高级的用例(例如正确处理正在停止的工作),您应了解 WorkManager 中的线程处理和并发机制。
WorkManager 提供了四种不同类型的工作基元:
Worker
是最简单的实现,我们已在前面几节进行了介绍。WorkManager 会在后台线程中自动运行该基元(您可以将它替换掉)。请参阅工作器中的线程处理,详细了解 Worker
实例中的线程处理。
CoroutineWorker
是为 Kotlin 用户建议的实现。CoroutineWorker
实例公开了后台工作的一个挂起函数。默认情况下,这些实例运行默认的 Dispatcher
,但您可以进行自定义。请参阅 CoroutineWorker 中的线程处理,详细了解 CoroutineWorker
实例中的线程处理。
RxWorker
是为 RxJava 用户建议的实现。如果您有很多现有异步代码是用 RxJava 建模的,则应使用 RxWorker。与所有 RxJava 概念一样,您可以自由选择所需的线程处理策略。请参阅 RxWorker 中的线程处理,详细了解 RxWorker
实例中的线程处理。
ListenableWorker
是 Worker
、CoroutineWorker
和 RxWorker
的基类。这个类专为需要与基于回调的异步 API(例如 FusedLocationProviderClient
)进行交互并且不使用 RxJava 的 Java 开发者而设计。请参阅 ListenableWorker 中的线程处理,详细了解 ListenableWorker
实例中的线程处理。
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"没有我需要的信息"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"太复杂/步骤太多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"内容需要更新"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/代码问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-12-10 UTC.