What is the best way to schedule tasks on an interval within the context of a certain composable? Meaning the task only runs while the composable is on screen.
b
Big Chungus
02/14/2022, 8:04 AM
Launched effect with infinite loop and delay?
z
Zach Klippenstein (he/him) [MOD]
02/16/2022, 1:50 PM
By “on screen” do you mean composed or actually visible, ie not clipped by any of its parents?
c
Cody Mikol
02/16/2022, 9:02 PM
Composed
s
Stylianos Gakis
02/17/2022, 7:09 AM
Then exactly what Martynas said. A simple
LaunchedEffect(Unit)
and wrap your thing inside a
Copy code
while(isActive) {
//your stuff
delay(1_000)
}
Things will just work plus cancel themselves due to automatic cancellation (if the things you call cooperate with cancellation as well).