I am currently attempting to refresh data from a server at a regular interval, only when the UI is displayed. So when back or home is pressed, the checks will stop. When I return, it will continue again.
I thought I could use a LaunchedEffect, as it runs in a CoroutineScope. I thought that this would result in the Coroutine automatically cancelling when going home. However, I am not sure how it is linked to the lifecycle. It remains active in the background.
Copy code
LaunchedEffect(true) {
while (isActive) {
delay(60000L)
vm.getData()
}
}
Is there a better pattern to use in this case?
a
Adam Powell
03/10/2021, 5:24 PM
This will remain active in the background, yes. There are a few new APIs in flight for