Reputation: 1427
In my android app I set
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
to enable cache for webview. The question is,when the web content changed(that I don't know),it still use the old cached content. How can I make it automatically recache the content when the online web content has been changed without not using the cache?
Any suggestion would be appreciated.
Upvotes: 1
Views: 2465
Reputation:
There is way to check if content on server is changed. Try FCM. On every content submit send notification to every app. Then On message received method clear your webview cache. In this manner whenever content on server will change user will see updated content. I'm using this method and working great for me.
Upvotes: 3
Reputation: 7087
I believe there is no way you can identify if webpage content is changed.
But, when you enable caching to webview, it automatically provides an expiry to webview cache, which means, if webView cache is expired it will load the webpage again. This is possible if you use WebSetting.LOAD_DEFAULT
If you feel the content of html page may change more frequently, then you should not use WebSetting.LOAD_CACHE_ELSE_NETWORK
since, according to doc:
public static final int LOAD_CACHE_ELSE_NETWORK
Use cached resources when they are available, even if they have expired. Otherwise load resources from the network.
This will load cached version of html page even if it is expired.
Upvotes: 5