DessertTask 中文点这里
easy start task in application in different threads
AndroidX Please use
implementation 'com.github.flalaorg:DessertTask:$version'
Android-support Please useimplementation 'com.github.flalaorg:DessertTask-Android:$version'
- How to initialize, we recommend the following
DessertDispatcher.init(this)- If you want to get an instance of it
// Chained call
DessertDispatcher.init(this)
.build()or
// Get singleton
DessertDispatcher.getInstance()- Now you can add tasks as you like
create(Class<Interface>, InterfaceImpl())
// such as
create(ITask::class.java, TaskImpl())or
//DessertTask is abstract you should extend it, Then put its implementation class in
addTask(DessertTask())
// such as
addTask(TaskOne())or
addTask(easyTask {
Log.d("EasyTask wow", "Start: ${Thread.currentThread().name}")
})- End you should use
start()to Start Tasks - Sample
DessertDispatcher.init(this)
.build()
.create(ITask::class.java, TaskImpl())
.addTask(TaskOne())
.addTask(easyTask {
Log.d("EasyTask wow", "Start: ${Thread.currentThread().name}")
})
.start()priorityThe priority range can be specified according to the importance and workload of the taskneedRunAsSoonMeaning as its namerunOnTask execution thread pool, can be specified, generally defaultdependOnDependent TaskdependOnByNameThe name of the dependent task, which can be the method name or the class nameneedWaitWhether the Task executed by the asynchronous thread needs to wait when await is calledrunOnMainThreadMeaning as its nameonlyInMainProcessMeaning as its nametailRunnableTasks that need to be performed after the main task is completedneedCallDoes the Task require a callbackMore recommended now usetailRunnablecallbackMeaning as its nameMore recommended now usetailRunnable
@TaskMarking methods, the method will be converted toDessertTask@TaskConfigTask Attributes setting, but there are some differences
prioritycan only be selected inPriorities.THREAD_PRIORITY_FOREGROUND、Priorities.THREAD_PRIORITY_BACKGROUND、Priorities.THREAD_PRIORITY_LOWESTrunOnExecuteis the same asrunOn, but can only be selected inExecutors.IOandExecutors.CPUdependOnis the same asdependonByNametailRunnablemethod name who annotation used@TaskTailRunnabletargetCallbackmethod name who annotation used@TaskCallback
@TaskCallbackMarking methods, the method will be converted tocallback@TaskTailRunnableMarking methods, the method will be converted totailRunnable