Site icon The Winter Blog

Goodbye handler, hello lifecycle coroutines

I just replaced this:

a_view?.handler?.postDelayed(Runnable {
    doSomething()
}, 500)

with this:

viewLifecycleOwner.lifecycleScope.launchWhenResumed {
    delay(500)
    doSomething()
}

It makes me very happy*!


* Specially because I’ll get hell if I try to use this lifecycle+coroutines solution at work.

Exit mobile version