I am new to using co routines .... I am trying something like this
- Start a thread(using co routines) on
resume()of activity - Run the thread indifinately
- Set textview every
5 seconds - Stop
onPause()of activity life cycle
I am new to using co routines .... I am trying something like this
resume() of activity5 secondsonPause() of activity life cycleYou can do this
private var job: Job? = null
override fun onStart() {
super.onStart()
job = lifecycleScope.launch {
while (true) {
/* do work */
delay(5000L)
}
}
}
override fun onStop() {
job?.cancel()
job = null
super.onStop()
}