Home > database >  How to call a function every 5 second in Jetpack Compose
How to call a function every 5 second in Jetpack Compose

Time:11-24

I want to call my ViewModel's function every 5 seconds. What is the best way to do that in Jetpack Compose?

CodePudding user response:

It depends when you want this behaviour to start and end.

This will run as long as your composable remains in the composition:

LaunchedEffect(Unit) {
    while(true) {
        vm.someMethod()
        delay(5000)
    }
}
  • Related