在 enqueue 之后永远不会调用 doWork()方法,来自 MainActivity 的 Relavent 代码,我试图将其排入队列
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()
}
}
}
使用的库
ext.android_support_version = '28.0.0'
ext.android_multidex_version = '1.0.3'
ext.androidx_work = '1.0.0-alpha12'
ext.kotlin_version = '1.2.71'
ext.lifecycle_version = '1.1.1'
ext.retrofit_version = '2.4.0'
ext.dagger2_version = '2.16'
ext.room_version = '1.1.1'
ext.gradle_version = '3.1.0'
ext.moshi_version = "1.8.0"
ext.caroutines_version = "0.26.1"
ext.junit_version = "4.12"
ext.stetho_version = "1.5.0"
ext.rx_java_version = "2.2.0"
ext.rx_android_version = "2.1.0"