mutablelist - Why does rememberMutableStateListOf doesn't work with Tablet? - Stack Overflow

admin2025-04-15  3

I have a generic rememberMutableStateListOf used across my app that keeps lists if screen configuration changes, like rotation.

@Composable
fun <T> rememberMutableStateListOf(vararg elements: T): SnapshotStateList<T> {
    return rememberSaveable(
        saver = listSaver(
            save = { stateList -> stateList.toList() },
            restore = { list -> list.toMutableStateList() }
        )
    ) {
        elements.toList().toMutableStateList()
    }
}

The problem is, it works with all devices, but not with tablet. Once the screen is rotated, it shows no elements in, e.g. from portrait to landscape. But when rotating back from landscape to portrait the list contains elements like before.

I do not have a physical device and use the Android emulator (resizable).

What might be the problem?

EDIT:

That's not only for rememberMutableStateListOf, but also other saveable variables like

var done by rememberSaveable { mutableStateOf(false) }

No saveable variable survives screen rotation, only ViewModel.

转载请注明原文地址:http://www.anycun.com/QandA/1744728549a86794.html