如何在 Android worker 中检测前一个 worker 失败的一系列 Worker

How to detect within an Android worker that within a sequence of Workers a previous worker has failed

我正在调查 Android 名工人。

api "androidx.work:work-runtime:2.6.0-alpha01"

我正在创建独特的工作,需要多个工人依次 运行

Worker_A -> Worker_B -> Worker_C

如果 Worker_AWorker_B returns Result.failure() 有什么方法可以在 Worker_C[=17= 内检测到这一点]

如 WorkManager 中所述 Chaining Work documentation:

Chains of OneTimeWorkRequest execute sequentially as long as their work completes successfully (that is, they return a Result.success()). Work requests may fail or be cancelled while running, which has downstream effects on dependent work requests.

回答你的问题:

In the event either Worker_A or Worker_B returns Result.failure() is there any approach I can take to detect this within Worker_C?

不,Worker_C 无法检测到 Worker_AWorker_B 的故障,因为它根本不会是 运行。

Chaining and Worker statuses 对此进行了详细介绍。