我可以在 PeriodicWorkRequestBuilder 中每次启动 doWork() 时更改输入数据吗

Can I change Input Data every start doWork() in PeriodicWorkRequestBuilder

我可以设置输入数据([someDataChangeEveryWorkerStart])

val uploadWorkRequest = PeriodicWorkRequestBuilder<UploadWorker>((1, TimeUnit.HOURS))
    .setInputData(imageData)
    .build()

哪个图像数据每 1 小时更改一次

在您的 Worker 中,当您完成方法 doWork 时,您应该 enqueueUniquePeriodicWork 使用新数据并使用 ExistingPeriodicWorkPolicy.REPLACE 替换当前工作人员

val uploadWorkRequest = PeriodicWorkRequestBuilder<UploadWorker>((1, TimeUnit.HOURS))
    .setInputData(newImageData)
    .build()
WorkManager.getInstance(applicationContext).enqueueUniquePeriodicWork(
        “YourWorkerTag”,
        ExistingPeriodicWorkPolicy.REPLACE,
        uploadWorkRequest)