为什么android Webview默认不检查缓存?

xdu*_*ine 9 android caching android-webview

我有一个使用应用程序缓存的webview.我启动了与网络连接的应用程序,以加载/缓存页面.现在,在关闭wifi(和3g - 没有网络连接)并启动应用程序后,我会看到"android无法加载页面"页面.奇怪的是,如果我重新加载webview,它会从缓存中加载页面.如果无法连接到网络,为什么不从缓存中加载此页面?

我正在使用带有cache.manifest的HTML5 Application Cache.这是我的webview代码,用于启用此功能:

webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setAppCacheMaxSize(1024*1024*8);
webview.getSettings().setAppCachePath("/data/data/com.my.package/cache");
webview.getSettings().setAllowFileAccess(true);
webview.getSettings().setAppCacheEnabled(true);
Run Code Online (Sandbox Code Playgroud)

我试过加入:

weview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); 
Run Code Online (Sandbox Code Playgroud)

但它没有帮助.

Pau*_*sma 0

检查您请求的 URL 是否不是重定向。如果是,缓存也将指向该重定向,并且 WebView 不会从缓存中读取结果重定向。

我花了一些时间才弄清楚这就是我的案例中发生的情况。