workManager 基本使用

创建新的work

class CleanUpWorker(context: Context,params:WorkerParameters) : Worker(context,params){
    private val TAG by lazy {
        this.javaClass.simpleName
    }

    override fun doWork(): Result {
        try {
            /*todo  自己的耗时逻辑*/
            return Result.success()
        }   catch (e:Exception){
            return Result.failure()
        }
    }
}

执行

       val  request = OneTimeWorkRequest.from(CleanUpWorker::class.java)
        workManager.enqueue(request)

你可能感兴趣的:(workManager 基本使用)