Android WebView cache doesn't expire

4.9k Views Asked by At

in my Android App I use a WebView and got a problem with caching. After a file is cached the WebView just keeps it forever (or at least until I delete the cache manually).

In the Apache Access-Log I see that the WebView doesn't send requests once the file is cached. How can I setup the WebView to send requests for checking if the file is expired by using common ETags and HTTP-Code 304? On a desktop browser(Firefox, Chrome) the caching works as expected.

Here is my code:

    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.setWebViewClient(new EWebViewClient(this));
    webView.getSettings().setBuiltInZoomControls(false);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    webView.setWebChromeClient(new EWebChromeClient(this));
    webView.setBackgroundColor(Color.argb(1,0,0,0));
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    webView.loadUrl(url);

EWebViewClient only overwrites: "shouldOverrideUrlLoading, onPageFinished, onLoadResource, onReceivedError"

I really appreciate any help you can provide.

0

There are 0 best solutions below