What would be the most proper way to address the f...
# coroutines
t
What would be the most proper way to address the following kind of patterns in coroutine world? Main gains would be readability and binding to coroutineScope to be sure that the runnable does not run after scope ending if we forget to remove the callback at the proper places.
Copy code
private val unregisterInputRequestListener = Runnable { }

    override fun onActivityResumed(activity: Activity) {
        uiHandler.removeCallbacks(unregisterInputRequestListener)
    }

    override fun onActivityPaused(activity: Activity) {
        uiHandler.postDelayed(unregisterInputRequestListener, 1500)
    }
Copy code
private val dimRunnable = Runnable {}

    private fun resetDimTimer() {
        uiHandler.removeCallbacks(dimRunnable)
        uiHandler.postDelayed(dimRunnable, DIM_DURATION)
    }