How to disable cache in android webview?

前端 未结 3 770
感动是毒
感动是毒 2020-12-13 23:23

In my android webview my webpage is loading even without internet because of cache, so i want to disable cache in android webview, can anyone help me how to do this?

相关标签:
3条回答
  • 2020-12-14 00:08

    I had the same problem. Even though I had the below two lines, my webview was still loading old data.

    webview.getSettings().setAppCacheEnabled(false); webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    My mistake was, i had this cache related settings after I called the loadUrl() on webview. After I moved these cache settings ahead of loadUrl(), i had everything working as expected.

    0 讨论(0)
  • 2020-12-14 00:12

    Please add below code

            mWebView.getSettings().setAppCacheEnabled(false);
            mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    

    Please remove app from history task and test its working.

    0 讨论(0)
  • 2020-12-14 00:18

    Just after creating your webview, before loading any pages, you can clear the cache.

    myBrowser.clearCache(true) - the boolean indicates if you wish to delete the cached files on disk as well.

    The documentation is here if you wish to dig further.

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