解决方案:
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) {
}
}
}

本文提供了一种在Android应用中正确销毁WebView组件的方法,通过一系列步骤确保内存得到释放,避免内存泄漏问题。包括停止加载、禁用JavaScript、清除历史记录、移除视图及调用销毁方法。
1003

被折叠的 条评论
为什么被折叠?



