I have a HTML template file which is used at multiple places one of them is it is used to get loaded as a webview in few android apps, How can I make sure everytime webview is loaded it loads the most recent version(No cache) without making any changes in app settings.
3 Answers
You can try something like this:
WebView webview = new WebView(this); webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); Check out more here
Comments
When WebView finishes a page everytime, clear the cache. Something like this in your WebViewClient:
@Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); view.clearCache(true); } 1 Comment
Amit23588
Thanks @Masum for answering this, but my problem is I can only control the content of HTML file I have no control over the webview client and its settings, Is there anything that I can add in HTML template which will override the webview cache settings.
Just after creating your WebView, before loading any pages, you can clear the cache.
browser.clearCache(true); and one other way is to Override onPageFinished() which is called each time a page gets loaded, so you could clear cache in it.
@Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); view.clearCache(true); }