• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps WebView Caching

I am working on app with single Fragment and Webview. I have one Webview, created and loaded in a fragment. Here are my caching permissions:

websettings.setAppCachePath(getContext().getCacheDir().toString());
websettings.setAppCacheEnabled(true);
websettings.setCacheMode(WebSettings.LOAD_DEFAULT);
websettings.setAppCacheEnabled(true);

Documentation is not clear if this caching will work if WebView is recreated? Do I have to keep the WebView itself in memory for caching to work? Everytime, I reload a new page in the fragment the cache of the old page is gone. Webview is a view so I don't see how I can keep these around for long. yet I would like to cache and not go to network for most recent page visits.
 
Last edited:
I've not used this myself, but I would expect that the webview cache is somewhere on the internal memory storage. So in my opinion there is no reason why the webview could not retrieve the cached page when you reload the fragment.

I wonder if these links may help you, I see they are calling restoreState() on the webview. You may already be doing this though.

http://stackoverflow.com/questions/18479519/how-to-save-restore-webview-state
http://www.coderanch.com/t/605255/Android/Mobile/Android-WebView-loading-page-cache

You can also implement your own cache if things are really not working, to give you total control over the caching.
 
If i remember what I read right, I think that as long as the app is running (even if it is closed) it will have the cache still intact. You have to exit the app and shut it down completely before the cache is deleted unless you do so your self as LV426 links pointed out.
 
Back
Top Bottom