In Java it works by accepting an object which implements runnable :
Thread myThread = new Thread(new myRunnable())
where myRunnable
Firstly, create a function for set default propery
fun thread(
start: Boolean = true,
isDaemon: Boolean = false,
contextClassLoader: ClassLoader? = null,
name: String? = null,
priority: Int = -1,
block: () -> Unit
): Thread
then perform background operation calling this function
thread(start = true) {
//Do background tasks...
}
Or kotlin coroutines also can be used to perform background task
GlobalScope.launch {
//TODO("do background task...")
withContext(Dispatchers.Main) {
// TODO("Update UI")
}
//TODO("do background task...")
}