WebView Loads slowly in android?

时光总嘲笑我的痴心妄想 提交于 2020-01-01 18:58:05

问题


I am working on a webView in an app, where content which webview load changes when a button is pressed (two buttons next and previous , they just change the content in webview). But after pressing 3 -4 times it starts to hang there is nothing printed on logcat, the button remains pressed for 15-20 sec and then the next data is loaded.

I have used these to clear out webview.db and cache:-

context.this.deleteDatabase("webview.db");
context.this.deleteDatabase("webviewCache.db");

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

But still it hangs.How can I speed it up?Please help?

UPDATED:

   public void setWebView(String QuestionParent,String QuestionNumber)
    {


        WebSettings webSettings = questionWeb.getSettings();

        webSettings.setDefaultFontSize(24);

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


        questionWeb.loadDataWithBaseURL("",integralParse.htmlParse(questionCode,"mnt/sdcard/faData/"+QuestionParent+"/"+QuestionNumber),"text/html","UTF-8","");
    }

I am using this method on button press. integralParse.htmlParse() method returns a html text .


回答1:


Are you handling webView navigation properly? See this tutorial on the official docs:

https://developer.android.com/guide/webapps/webview.html#HandlingNavigation

if you are just using loadData() then you can try setting hardware acceleration on in the manifest file like this:

android:hardwareAccelerated="true"

add it at the application level, i.e in the tag of your AndroidManifest.xml file

After this point, it really depends on your device. If you have a high end device, images will be rendered quickly otherwise they will take time since webView is using webkit hardware acceleration and this depends on your device configuration.

if you still need speed, you can try making a fully native app without webview. Everything will be smooth as butter. No webkit, no html and much greater control.

Good luck :-)



来源:https://stackoverflow.com/questions/12740082/webview-loads-slowly-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!