dazza5000
06/27/2022, 6:22 PMgildor
06/28/2022, 4:05 AMdazza5000
06/28/2022, 4:10 PMgildor
06/29/2022, 2:12 AMprivate val logoutJob: Job? = null
private val coroutineScope: CoroutineScope = TODO() // It can be GlobalScope in this case, depends on when you want this logout work
fun startLogoutTimer() {
logoutJob.cancel()
logoutJob = coroutineScope.launch {
delay(LOGOUT_TIME)
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
// Body of your doInBackground method of AsyncTasks
}
}
}
If I would implement something like this I would probably instead implement it on base of Flow, though it’s a bit more complicated to explain and code will be much more different from this example
In general, it’s quite a big topic, I see that you still use asynctask there, which also really should be rewritten to coroutines