解决方案:
onDestory中加入如下代码,wvTerm是webview的id:
if (dataBinding?.wvTerm != null) {
val parent = dataBinding?.wvTerm?.parent
(parent as? ViewGroup)?.removeView(dataBinding?.wvTerm)
dataBinding?.wvTerm?.apply {
stopLoading()
settings.javaScriptEnabled = false
clearHistory()
removeAllViews()
try {
destroy()
} catch (e: Exception) {
}
}
}