Android webview loading data performance very slow

前端 未结 3 1956
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 13:24

Hi I am working on one application, In that I am using Android WebView. Whenever I launch webview activity, loading data in string html format from test.txt file. test.txt f

相关标签:
3条回答
  • 2020-11-27 13:55

    I have tried below code its working faster for me

    // For API level below 18 (This method was deprecated in API level 18)
    webview.getSettings().setRenderPriority(RenderPriority.HIGH); 
    
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    if (Build.VERSION.SDK_INT >= 19) {
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }       
    else {
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    
    0 讨论(0)
  • 2020-11-27 14:05

    I think the following works best:

    if (Build.VERSION.SDK_INT >= 19) {
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }       
    else {
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    

    Android 19 has Chromium engine for WebView. I guess it works better with hardware acceleration.

    For more info Android 4.4 KitKat, the browser and the Chrome WebView

    Hardware Acceleration also do's the trick.You can use it in different levels in your application.

    Application level

    <application android:hardwareAccelerated="true" ...>
    

    Activity level

    <application android:hardwareAccelerated="true">
        <activity ... />
        <activity android:hardwareAccelerated="false" />
    </application>
    

    Window level

    getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
        WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
    

    View level

    myView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    

    But as already mentioned in your question can you elaborate the side effects for this ?

    0 讨论(0)
  • 2020-11-27 14:06

    In case anyone ends up here still beating their heads against the wall trying to make WebViews render faster, try Crosswalk's XWalkView. Made a huge difference in our app.

    0 讨论(0)
提交回复
热议问题