Fin
05/27/2026, 4:53 AMretain API, though its docs explicitly recommend against using it with Views.
Is there a stable, recommended way to handle this?Pablichjenkov
05/27/2026, 5:31 AMFin
05/27/2026, 7:02 AMPablichjenkov
05/27/2026, 7:11 AMKyriakos
05/27/2026, 8:40 AMfun saveState(outState: android.os.Bundle) {
webview.saveState(outState)
}
fun restoreState(inState: android.os.Bundle) {
webview.restoreState(inState)
}Fin
05/27/2026, 11:51 AMTepes Lucian Victor
05/27/2026, 12:46 PMretain . Not pretty but it does what i need. Not seen any memory issues, granted my app isn't WebView heavy and i have a full compose app with all the configChanges flags in the manifest. So even if i rotate or unfold a foldable the webview app state preserves since the activity doesn't get recreated.
var innerWebView by rememberRetained {
mutableStateOf<WebView?>(null)
}
AndroidView(
factory = { context ->
val webview = innerWebView
if (webview?.context === context) {
webview
} else {
WebView(context).also {
innerWebView = it
}
}
},
update = {
},
modifier = Modifier
.fillMaxSize(),
)