androidengineers.Book a session
โ† All interview questions
Jetpack ComposeBeginner2 min

A lesson is added to a mutable list, but Compose shows no change. Why?

Answer

remember { mutableListOf(...) } retains a list, but an ordinary list does not notify Compose when its elements change. Retaining an object and observing its mutations are separate concerns.

Example

For simple local UI state, replace the list value:

var topics by remember { mutableStateOf(listOf("Lifecycle")) }

Button(onClick = { topics = topics + "Saved state" }) {
    Text("Add topic")
}
topics.forEach { topic -> Text(topic) }

Another option is remember { mutableStateListOf<String>() }, whose structural mutations are observable. Choose one model consistently instead of mixing an observable wrapper with hidden mutable internals.

Common trap

Putting a mutable list inside a data class does not make its contents observable. Mutating that list and assigning the same object back can also fail to produce a distinguishable new state. Prefer immutable items and a new list when publishing screen state from a ViewModel.

Follow-up to practise

What if the list updates but a lesson title does not? Inspect the lesson object. A plain mutable title property inside an observable list is not automatically observable. Replace the lesson with an updated immutable value, or deliberately make the relevant property observable.

Reference

Android Developers: State and Jetpack Compose

Mark this when you can explain the answer in your own words.

Share & Help Others

Help fellow developers prepare for interviews

Sharing helps the Android community grow ๐Ÿ’š

Keep practising