dig*_*ino 6 android android-workmanager
有没有办法从 WorkManager Google API测试PERIODIC工作人员,而无需为每次执行至少等待 15 分钟?
我的意思是,它是一个调试应用程序,我正在通过 Android Studio 运行它,我不想等待这么长时间来测试我的功能。
你不能。
定期工作的最小间隔时间为 15 分钟,并且不能有初始延迟。你可以在课堂上找到证据WorkSpec.java。
/**
* Sets the periodic interval for this unit of work.
*
* @param intervalDuration The interval in milliseconds
*/
public void setPeriodic(long intervalDuration) {
if (intervalDuration < MIN_PERIODIC_INTERVAL_MILLIS) {
Logger.get().warning(TAG, String.format(
"Interval duration lesser than minimum allowed value; Changed to %s",
MIN_PERIODIC_INTERVAL_MILLIS));
intervalDuration = MIN_PERIODIC_INTERVAL_MILLIS;
}
setPeriodic(intervalDuration, intervalDuration);
}
Run Code Online (Sandbox Code Playgroud)
但还有其他方法可以解决这个问题。
OneTimeWorkRequest调试模式,例如:interface Scheduler {
fun schedule()
}
class DebugScheduler {
fun schedule() {
WorkManager.getInstance().enqueue(
OneTimeWorkRequest.Builder(MyWorker::class.java)
.build()
)
}
}
class ProductionScheduler {
fun schedule() {
// your actual scheduling logic
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1976 次 |
| 最近记录: |