This question is asked multiple times and it has answers that used to work. Recently in documentation said, they have removed this feature for security reasons. Only some li
Setting android:configChanges="orientation|screenSize" for Activity in Manifest for retaining the state of activity that has Webview in it, if there is no difference in layout for portrait and landscape view.
You can save Webview state as:
override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) webView.saveState(outState)
}
override fun onRestoreInstanceState(savedInstanceState: Bundle?) { super.onRestoreInstanceState(savedInstanceState) webView.restoreState(savedInstanceState)
}
and reload only if saved state is not null like:
if (savedInstanceState == null) {
webView.loadUrl("replace_with_your_url")
}