0

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 3

1

You can try something like this:

WebView webview = new WebView(this); webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 

Check out more here

Sign up to request clarification or add additional context in comments.

Comments

1

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

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.
0

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); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.