luke_c
08/27/2025, 7:43 AMAndroidView
which reads from a lambda passed into the function, which is stable
AndroidView(factory = { context ->
onViewCreated()
...
}
)
However this is causing the factory function to be called, and the underlying view to be re-created on every configuration change. The lambda is ultimately created this way:
val onViewEvent = remember(viewModel) { viewModel::onViewEvent }
val onViewCreated = { onViewEvent(SomeViewEvent) }
The problem I'm seeing is that remember
doesn't survive configuration changes, so onViewEvent
gets remember'd again with a new reference (even though the viewModel instance is the same) and we can't use rememberSaveable
with lambdas (and I'm not sure it feels right to do so!)
Has anyone dealt with this before and figured out a solution?Jonathan
08/27/2025, 3:09 PMremember {}
get preserved during configuration changes? I thought the entire compositions gets recreated since the Activity is getting recreated? Have you disabled that functionality first?Jonathan
08/27/2025, 3:10 PMprintln
statement in your Activities onCreate(Bundle)
and see if it get printed every time you rotate your device?Uli Bubenheimer
08/27/2025, 3:58 PMonViewEvent
changing. Is that what your question is about?