user3153083
user3153083

Reputation: 591

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

Upvotes: 56

Views: 56234

Answers (4)

MD. Shafiul Alam Biplob
MD. Shafiul Alam Biplob

Reputation: 1161

 webView.clearCache(true)
 webView.clearHistory()
 webView.settings.cacheMode = WebSettings.LOAD_NO_CACHE;

Those 3 methods before the loadUrl method worked for me. Don't forget to clear the app storage or uninstall the app completely to test for the first time.

Upvotes: 2

Piyush
Piyush

Reputation: 5737

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.

Upvotes: 66

MSD
MSD

Reputation: 2647

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.

Upvotes: 5

Mellson
Mellson

Reputation: 2948

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.

Upvotes: 35

Related Questions