0

I have a webview that is loading data and caching it , in the code below this cached data is being loaded if it is found

However I want the webview to reload from the network if it finds a change in the url rather than just loading the recent cached item

Is there a way for me to compare the current url with the cached one , or someway to have the webview load the cache if the same or the new one when different

wvStructue.settings.javaScriptEnabled=true
        wvStructue.settings.loadWithOverviewMode = true
        wvStructue.settings.useWideViewPort = true
        wvStructue.settings.databaseEnabled = true
        wvStructue.settings.domStorageEnabled = true
        wvStructue.settings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK
        wvStructue.settings.builtInZoomControls = true
        wvStructue.settings.displayZoomControls = false
GoonerJhh
  • 3
  • 4

1 Answers1

0

Refer this link

Set webview cache mode LOAD_CACHE_ELSE_NETWORK.

Override WebViewClient methods :

@SuppressWarnings("deprecation")
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            if (view.getUrl().equals(failingUrl)){
                showInternetConnectionError();
            }
            super.onReceivedError(view, errorCode, description, failingUrl);
        }

        @TargetApi(android.os.Build.VERSION_CODES.M)
        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            onReceivedError(view, error.getErrorCode(), error.getDescription().toString(), request.getUrl().toString());
        }
Siddarth Jain
  • 304
  • 1
  • 6