Issue
I've just created a WebView app that just basically opens a news website and tried to make it faster by storing some stuff in cache. The problem that came up was that whenever some new articles were added to the actual page, the app would not show them, since it already has the main page, along with some others that were visited, stored in cache. So if, for example, you first opened the app, surfed the web for a couple of minutes, and then opened it after a couple of days, it wouldn't have any new articles, just the ones that came before you first opened the app.
Is there any way I can effectively clear the cache when a user starts/kills the app using some code?
Are there any other solutions to this problem that would not make the app much slower?
Solution
You can use the clearCache method. You may call it every time the application load, to may the app clear the cache stored on the previous session. Check out the documentation: https://developer.android.com/reference/android/webkit/WebView.html#clearCache(boolean)
WebView mWebView;
mWebView.clearCache(true);
you pass 'true' as parameters to clear not only the RAM cache:
Clears the resource cache. Note that the cache is per-application, so this will clear the cache for all WebViews used.
Answered By - Rander Gabriel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.