Home > Software engineering >  How to change the Default value of a variable after some time?
How to change the Default value of a variable after some time?

Time:09-18

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?

CodePudding user response:

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.

  • Related