如何使用工作要求在Kotlin的工作经理中定期工作请求链接
我有下面的三个工作请求
val imageWorker = OneTimeWorkRequestBuilder<ImageUploadingWorker>()
.setConstraints(constraints)
.addTag("imageWork")
.build()
val gpSurveyWorker = OneTimeWorkRequestBuilder<GpSurveyUploadingWorker>()
.setConstraints(constraints)
.addTag("gpSurveyWork")
.build()
val gpSurveyListWorker = OneTimeWorkRequestBuilder<SurveyListUpdateWorker>()
.setConstraints(constraints)
.addTag("gpSurveyList")
.build()
,我将他们纳入工作经理
workManager.beginWith(imageWorker)
.then(gpSurveyWorker)
.then(gpSurveyListWorker)
.enqueue()
,这是完美的工作,但是我希望定期执行每4小时后执行的定期工作请求,我不能单独安排它们,因为每个请求都取决于先前的请求。我需要定期使用它,因为它将我的离线数据同步到服务器。我读到,在定期工作请求中不可能进行链接,因此在这种情况下,是否有任何方法可以在第一个请求后执行第一个请求,而在第一个请求后执行其他请求。
请帮助我建立这些工作请求的链接。
提前致谢。
I have three work request as below
val imageWorker = OneTimeWorkRequestBuilder<ImageUploadingWorker>()
.setConstraints(constraints)
.addTag("imageWork")
.build()
val gpSurveyWorker = OneTimeWorkRequestBuilder<GpSurveyUploadingWorker>()
.setConstraints(constraints)
.addTag("gpSurveyWork")
.build()
val gpSurveyListWorker = OneTimeWorkRequestBuilder<SurveyListUpdateWorker>()
.setConstraints(constraints)
.addTag("gpSurveyList")
.build()
and I enqueue them in work Manager as
workManager.beginWith(imageWorker)
.then(gpSurveyWorker)
.then(gpSurveyListWorker)
.enqueue()
And this work perfectly, but I want periodic work request that executes after every 4 hours, I can not schedule them individually because each request depends on the previous request. And I need it periodically because it syncs my offline data to the server. I read that chaining is not possible in periodic work requests, so in this case, is there any way to create the first request as periodic and the other request are executed after the first request.
Please help me in creating chaining of these work requests.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想链接一些定期工作请求,那么根据我所知,最好的方法是首先创建一个定期工作请求,在Dowork()方法中的工作类别中,只需将AA放置在三个或四个请求。
在这种情况下,您的第一个请求(定期工作请求)将执行所有其余三个请求(这是一次性请求)。
这样,您可以实现定期工作请求的链接。
If you want to chain some periodic work requests then the best way as per my knowledge is to first create a periodic work request and in the worker class inside the doWork() method just put aa the three or four requests and make them one Time request.
What happens in this situation is your first request(Periodic Work Request) will execute all the rest three requests (which are one-time requests).
In this way, you can achieve chaining of periodic work requests.