Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable cache in android webview?

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?

I am using following lines in my webview, but still i am not able to disable cache.

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

Please suggest me if there are some other methods

like image 658
user3153083 Avatar asked Jan 11 '14 07:01

user3153083


People also ask

How do I disable cache in Webview?

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

Does android Webview cache?

There are two caches in WebView: Web data caching (storing opened pages and resources) and H5 caching (AppCache).

Do cookies work in Webview?

By default this is set to true and the WebView accepts cookies.


2 Answers

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.

like image 86
Piyush Avatar answered Sep 19 '22 16:09

Piyush


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.

like image 31
Mellson Avatar answered Sep 20 '22 16:09

Mellson