Enhance webView performance (should be the same performance as native Web Browser)

后端 未结 2 1750
暗喜
暗喜 2020-12-02 05:57

My experience is that loading websites in a WebView is much slower than performing the same actions in the Android Web Browser. I can see that all files have been loaded in

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 06:26

    I ran into a similar issue, and after some heavy debugging noticed the native browser and WebView browser seem to be using different caches.

    This code can be used to disable the WebView cache, and made WebView much faster for me (though at the expense of not caching). Note that it uses private APIs, so by using it you're risking the code will break in future releases:

    try
    {
      Method m = CacheManager.class.getDeclaredMethod("setCacheDisabled", boolean.class);
      m.setAccessible(true);
      m.invoke(null, true);
    }
    catch (Throwable e)
    {
      Log.i("myapp","Reflection failed", e);
    }
    

提交回复
热议问题