0

Is it possible in KOTLIN or by remember in Jetpack Compose to change the value of a variable after some seconds?

For example, I have a variable var currentResult1 = remember { mutableStateOf(true) }. How can I say that after my activity opens, this currentResult1.value change to false after 1 second?

Reza Zeraati
  • 303
  • 1
  • 8

1 Answers1

1

Yes, you can change value of any MutableState value using LaunchedEffect or coroutineScope builder functions.

LaunchedEffect(Unit) {
    delay(1000)
    currentResult1.value = false
}

You can check out this answer how to use it for a timer that changes current value every second.

Thracian
  • 43,021
  • 16
  • 133
  • 222