WorkManager重试不起作用

时间:2018-08-21 16:39:53

标签: android android-jetpack android-workmanager

我有一个带有自定义backoff policy的WorkManager。但这是行不通的。

  • 我想在10秒的最小退避时间之后触发重试。
  • 如果Worker作业保留在WorkManager中,它们将在随机时间/重新启动应用程序后执行(即使指定的默认值为30秒,我也无法确定它们何时被触发)。

征服工人

appDidReceiveMessage:message

工人

const message = {
  data: {
    test: '123'
  }
  topic: 'example'
}
admin.messaging().send(message);

一些测试日志

public void startWorker() {
    Constraints constraints = new Constraints.Builder()
        .setRequiredNetworkType(NetworkType.CONNECTED)
        .build();
         Log.i("WorkManager", "starting workmanager");

        OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(UploadWorker.class)
                .setInitialDelay(5, TimeUnit.SECONDS)
                .setConstraints(constraints)
                .setBackoffCriteria(BackoffPolicy.LINEAR, WorkRequest.MIN_BACKOFF_MILLIS, TimeUnit.MILLISECONDS) // Custom retry not working
            .build();

    WorkManager.getInstance().enqueue(work);
}

我正在使用public class UploadWorker extends Worker { @Override public Worker.Result doWork() { // Do the work here--in this case, compress the stored images. // In this example no parameters are passed; the task is // assumed to be "compress the whole library." Log.i("WorkManager", "do some stuff " + getId()); // Indicate success or failure with your return value: return Result.RETRY; // (Returning RETRY tells WorkManager to try this task again // later; FAILURE says not to try again.) } } 的{​​{1}}版。

这是Bug还是我遗漏了一些东西?

1 个答案:

答案 0 :(得分:1)