入队后永远不会调用doWork()方法

时间:2018-12-12 08:56:32

标签: android android-workmanager

doWork()方法从入队后就再也不会调用,我试图从MainActivity入队的Relavent代码

this.canvas1 = document.getElementById('myChart1');
this.ctx1 = this.canvas1.getContext('2d');
let myChart1 = new Chart(this.ctx1, {
  type: 'bar',
  data: {
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
      datasets: [
          {
              label: '',
              backgroundColor: '#920909',
              borderColor: '#1E88E5',
              data: [63, 58, 82, 81, 56, 55, 41]
          },
          {
              label: '',
              backgroundColor: '#04033b',
              borderColor: '#7CB342',
              data: [27, 49, 45, 19, 87, 28, 90]
          },
          {
            label: '',
            backgroundColor: '#0c6790',
            borderColor: '#7CB342',
            data: [2, 50, 40, 29, 80, 27, 40]
          },
      ]
  },
  options: {
    responsive: false,
    display:true,
    scales: {
      yAxes:[{
        ticks:{
          beginAtZero:true
        }
      }]
    }
  }
});

Work类中的代码

val constraints = Constraints.Builder()
            .setRequiresBatteryNotLow(true)
            .build()
    val measurementSyncWork = OneTimeWorkRequest.Builder(MeasurementSyncWork::class.java).setConstraints(constraints).addTag(MeasurementSyncWork.TAG).build()
    var operation = WorkManager.getInstance()?.enqueue(measurementSyncWork)

}

使用的库

class MeasurementSyncWork(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {

companion object {
    const val TAG = "MeasurementSyncWork"
}

override fun doWork(): Result {
    return try {
        Result.success()
    } catch (throwable: Throwable) {
        Log.e(TAG, "Error while downloading measurements", throwable)
        Result.failure()
    }

}

0 个答案:

没有答案