本文共 573 字,大约阅读时间需要 1 分钟。
做项目的时候难免有一些页面需要用到webview来加载内容,最近使用时发现当加载的富文本内容过长时,闪退了造成oom。
之后查阅了一些内容,解决的方法:
1、使用三方框架加载网页(如agentweb)。
2、将xml中的webview用其他布局替换,比如:
然后再activity或fragment中
var customWebView : CustomWebView?=null
customWebView = CustomWebView(this)
customWebView!!.loadDataWithBaseURL(null, HtmlUtil.getHtmlData(t.full_text), "text/html", "utf-8", null)
newsde_fl.addView(customWebView)
之后
override fun onDestroy() { super.onDestroy() if(customWebView!=null){ customWebView?.onPause() customWebView?.destroy() } newsde_fl.removeAllViews()}
这是我的解决方法,有其他的方法的可以留言,一起学习。
转载地址:http://umczb.baihongyu.com/