开发者

Custom WebView Loading data is very Slow

I am working on an application where i am loading a开发者_JS百科 webpage from a an external url in a webview. The page loading takes a lot of time. If i open the same url in android's native browser that loads absolutely fine, but the performance is really bad in my custom webview.

here is the onCreate method of my customWebView Activity.

 protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_web_view);
    String uri = getIntent().getExtras().getString("uri");
    webView = (WebView) findViewById(R.id.cus_webview);
    dialog = ProgressDialog.show(CustomeWebViewActivity.this, "", "Loading. Please wait...", true, true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    webView.getSettings().setPluginsEnabled(false);
    webView.getSettings().setSupportMultipleWindows(false);
    webView.getSettings().setSupportZoom(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSavePassword(false);
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebChromeClient(new MyWebChromeClient());

    webView.clearCache(true);
    webView.clearHistory();
    webView.loadUrl(uri);
    webView.setWebViewClient(new MyWebView());
}

Is there anything i can do to reduce the loading time of webpage through my custom web view. please, any help is appreciated.


You can also try these

webView.getSettings().setRenderPriority(RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

and a conditional check.

if (Build.VERSION.SDK_INT >= 11){
    webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

and can also set hardwareAccelerated="true" in Menifest.xml file Taken out from multiple answers on SO but it helped.


Remove these two lines:

webView.clearCache(true);
webView.clearHistory();

and it will load faster.

You could do this after your page has loaded, and it will remove it all without the user noticing although it may make some odd behaviour. You could remove it in another thread or other method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜