Blog Infos
Author
Published
Topics
,
Published
Posted By: Udit Verma
@Composable
fun TimerScreen() {
LaunchedEffect(key1 = Unit, block = {
try {
startTimer(5000L) { // start a timer for 5 secs
println("Timer ended")
}
} catch(ex: Exception) {
println("timer cancelled")
}
})
}
suspend fun startTimer(time: Long, onTimerEnd: () -> Unit) {
delay(timeMillis = time)
onTimerEnd()
}
@Composable
fun TimerScreen1() {
Column(
modifier = Modifier
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
var timerDuration by remember {
mutableStateOf(1000L) // default value = 1 sec
}
Button({
timerDuration -= 1000
}) {
Text("-1 second")
}
Text(timerDuration.toString())
Button({
timerDuration += 1000
}) {
Text("+1 second")
}
Timer(timerDuration = timerDuration)
}
}
@Composable
fun Timer(timerDuration: Long) {
LaunchedEffect(key1 = timerDuration, block = {
try {
startTimer(timerDuration) {
println("Timer ended")
}
} catch (ex: Exception) {
println("timer cancelled")
}
})
}

Job Offers

Job Offers


    Android Engineer

    American Express
    London
    • Full Time
    apply now

    API Engineer

    American Express
    New York, USA
    • Full Time
    apply now

    Senior Android Developer

    Komoot
    remote
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

Jobs

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
In this post, we will explore composing a One-Tap phone number login experience using…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu