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()
priority
The priority range can be specified according to the importance and workload of the taskneedRunAsSoon
Meaning as its namerunOn
Task execution thread pool, can be specified, generally defaultdependOn
Dependent TaskdependOnByName
The name of the dependent task, which can be the method name or the class nameneedWait
Whether the Task executed by the asynchronous thread needs to wait when await is calledrunOnMainThread
Meaning as its nameonlyInMainProcess
Meaning as its nametailRunnable
Tasks that need to be performed after the main task is completedneedCall
Does the Task require a callbackMore recommended now usetailRunnable
callback
Meaning as its nameMore recommended now usetailRunnable
@Task
Marking methods, the method will be converted toDessertTask
@TaskConfig
Task Attributes setting, but there are some differences
priority
can only be selected inPriorities.THREAD_PRIORITY_FOREGROUND
、Priorities.THREAD_PRIORITY_BACKGROUND
、Priorities.THREAD_PRIORITY_LOWEST
runOnExecute
is the same asrunOn
, but can only be selected inExecutors.IO
andExecutors.CPU
dependOn
is the same asdependonByName
tailRunnable
method name who annotation used@TaskTailRunnable
targetCallback
method name who annotation used@TaskCallback
@TaskCallback
Marking methods, the method will be converted tocallback
@TaskTailRunnable
Marking methods, the method will be converted totailRunnable