如何提高Android WebView性能?

时间:2012-06-25 12:58:22

标签: android performance webview android-webview

我正在构建一个加载存储在我的Android设备上的HTML文件的应用程序。这些文件通常很大(例如6MB)。如果我加载这些HTML文件,显示它们需要相当长的时间(20到25秒)。谁能给我一些关于如何改善加载时间的建议? 我到目前为止尝试的代码:

final WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl("file:///android_asset/content.html");
webView.getSettings().setCacheMode(<all cache modes>)

我在Android 2.3和4.0上试过这个,Android 4.0的表现实际上差于2.3。

有关如何提高绩效的任何提示?

2 个答案:

答案 0 :(得分:1)

真的是一个广泛的讨论。您可能需要更具体。所以这就是......

  1. 通常会加快您的网页速度 - http://developer.yahoo.com/performance/rules.html

  2. 如果一次加载多个文件异步加载--http://developer.android.com/reference/android/os/AsyncTask.html

  3. 尽可能最小化图片或最后加载

  4. public void loadDataWithBaseURL(String baseUrl,String data,String mimeType,String encoding,String historyUrl)并将其缓存以供以后用于加载第二次或第三次更快

答案 1 :(得分:0)

好的,请尝试使用loadData方法,它可能会更快一些。

String summary;

...//convert your file to a string and store in summary variable

webview.loadData(summary, "text/html", null);