I have a class in Kotlin (Jetpack compose) with a variable title and an exoplayer that updates the title.
class Player{
var title by mutableStatOf("value")
....
title= "new value"
...
}
@Composable
fun Display(){
val player = Player()
player.title?.let{
Text(it)
}
}
In the user interface an instance of the class is created and the title displayed but it remains unchanged after being updated in the class. Can someone help?
You forgot to remember
the player instance. Here, when you change title
, your composable is recomposed because it reads the title. But when it is recomposed, you create new instance of Player
with the default title.
val player = remember { Player() }