Android architecture has a new components WorkManager.
From the example,
class CompressWorker(context : Context, params : WorkerParameters)
: Worker(context, params) {
override fun doWork(): Result {
// 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."
myCompress()
// Indicate success or failure with your return value:
return Result.SUCCESS
// (Returning RETRY tells WorkManager to try this task again
// later; FAILURE says not to try again.)
}
}
val compressionWork = OneTimeWorkRequestBuilder<CompressWorker>().build()
How can I create a Worker
that accept parameters in constructor or doWork
?