Android WebView isn't loading cached Website if there is no connection Android WebView isn't loading cached Website if there is no connection android android

Android WebView isn't loading cached Website if there is no connection


Your use of

engine.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

is telling the WebView to load the page from cache, but if it needs anything that isn't in the cache, it looks to the network, and when you have no connection, it will just give you the "page could not be loaded error." This is because sadly not everything is stored in the cache and even with this setting, you will notice the browser using the network.

The only way to get the WebView to ignore no connection is to use the

engine.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);

setting instead. Some images will not load with this setting (because they weren't cached) but it will still load everything it finds in the cache.


One other note unrelated to your question is that in your code, you have setAppCacheMaxSize being used and that has been deprecated in API 18 and above because the WebView manages the cache size itself, so just a heads up about that.