简体   繁体   中英

How to improve Android WebView performance?

I am building an application which loads HTML files stored on my android device. The files are typically quite large(6MB for example). If I load these HTML files it takes quite a long time to display them(20 to 25 seconds). Can anyone give me some advice about how to improve this loading time? code I tried so far:

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

I tried this on android 2.3 and 4.0, Android 4.0 performs actually worse then 2.3.

Any hints about how to improve performance?

Really a broad discussion. You might need to be more specific. So here it goes....

  1. In general speed up your pages -- http://developer.yahoo.com/performance/rules.html

  2. If loading more than one file at a time load asynchronously --http://developer.android.com/reference/android/os/AsyncTask.html

  3. Minimize pictures if at all possible or load them last

  4. public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) and cache it for later use to load faster 2nd or third time

OK so try the loadData method, it might be a bit faster.

String summary;

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM