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



Can I setInputData([someDataChangeEveryWorkerStart](

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

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

当你完成方法doWork时,在你的Worker里面,你应该enqueueUniquePeriodicWork新数据并使用ExistingPeriodicWorkPolicy.REPLACE来替换当前的工作线程

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

相关内容

  • 没有找到相关文章

最新更新