關於webview加載帶圖文的html格式數據


webview.loadDataWithBaseURL(null, data + "", "text/html", "utf-8", null);

注意:上述圖片的路徑為相對路徑,用webview加載時無法加載出來,應改為http://前綴的網絡路徑;

webview使用時出現的內存泄漏問題注意處理!

@Override
protected void onDestroy() {
super.onDestroy();
//System.exit(0);
if(infoDetailContentWeb!=null) {
infoDetailContentWeb.setVisibility(View.GONE);
infoDetailContentWeb.removeAllViews();
infoDetailContentWeb.destroy();
releaseAllWebViewCallback();
}
}

/**
* 防止內存泄露
*/
public void releaseAllWebViewCallback() {
if (android.os.Build.VERSION.SDK_INT < 16) {
try {
Field field = WebView.class.getDeclaredField("mWebViewCore");
field = field.getType().getDeclaredField("mBrowserFrame");
field = field.getType().getDeclaredField("sConfigCallback");
field.setAccessible(true);
field.set(null, null);
} catch (NoSuchFieldException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
} catch (IllegalAccessException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
} else {
try {
Field sConfigCallback = Class.forName("android.webkit.BrowserFrame").getDeclaredField("sConfigCallback");
if (sConfigCallback != null) {
sConfigCallback.setAccessible(true);
sConfigCallback.set(null, null);
}
} catch (NoSuchFieldException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
} catch (IllegalAccessException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
}

}
注意:還要在相應Activity的清單配置文件里面配置process!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM