WorkManager的PeriodicWorkRequest是否真的对任何人重复? [英] Is WorkManager's PeriodicWorkRequest really repeating for anyone?

查看:309
本文介绍了WorkManager的PeriodicWorkRequest是否真的对任何人重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试每15分钟执行一次重复的任务,但从未调用过Worker#doWork,甚至第一次也没有(在Nexus 6P-Android 8上).但是,在Android 8模拟器上进行测试时,我观察到在安排工作之后不久便会第一次调用它,但是再也不会重复了.我做错了什么?

I have tried making a repeated task every 15 minutes but Worker#doWork NEVER gets called, not even the very first time (on Nexus 6P - Android 8). However, when testing on an Android 8 emulator, I observed that it gets called the first time pretty soon after the work is scheduled, however it never repeats again. What did I do wrong?

build.gradle:

build.gradle:

implementation "android.arch.work:work-runtime-ktx:1.0.0-alpha07"

kotlin代码:

            val work = PeriodicWorkRequestBuilder<WidgetUpdateWorker>(MIN_PERIODIC_INTERVAL_MILLIS, TimeUnit.MILLISECONDS)
                .addTag(TAG_UPDATE_WIDGET)
                .build()

        WorkManager.getInstance().enqueueUniquePeriodicWork(TAG_UPDATE_WIDGET,
                ExistingPeriodicWorkPolicy.KEEP,
                work)

推荐答案

将您的应用构建依赖项替换为以下项.在我的应用程序中,PeriodicWork一直运行良好.我已经在很多设备上测试了该应用程序,但并非在所有设备上都测试过.请进行检查,并让我知道您是否遇到任何设备问题.

Replace your app build dependency with below one. PeriodicWork has been working fine in my app. I have tested the app on many devices but not all devices. Do check and let me know if you are facing the problem with any device.

implementation "android.arch.work:work-runtime-ktx:1.0.0-alpha10"

这篇关于WorkManager的PeriodicWorkRequest是否真的对任何人重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆