Article From:

The problem is: Rewriting the onKeyDown () method to make it goBack (), but the problem is that every time you go back to the WebView and return to the original page, there will be a flash in the middle.

I tried a lot of online methods and found that they were all nonsense.Injustice

Later, I realized that webView has caching mode in cache. How can we use different caching modes?

//Setting the cache mode
You need to change the pattern to LOAD_NO_CACHE!
But each time you have to re request, it costs a lot of resources, so you can rewrite a LOAD_NO_CACHE in onKeyDown (), and invoke the caching mode only when you return.
This way, you can refresh your whiteness without returning to the previous page.

private void initView() {  
    webview = (WebView) findViewById(;  
    webview.setWebViewClient(new WebViewClient() {  
        public boolean shouldOverrideUrlLoading(WebView view, String url) {  
            return true;  
    WebSettings settings = webview.getSettings();  
/* Rewriting the logic of the physical buttonsSuch@OverridePublic Boolean Boolean onKeyDown (int keyCode, KeyEvent KeyEvent event)If (KE)YCode = = = KeyEvent.KEYCODE_BACK; & & webview.canGoBack ()) {Return to the previous pageWebvIew.getSettings ().SetCacheMode (WebSettings.LOAD_NO_CACHE);Webview.goBack ();RetUrn true;    }  Return super.onKeyDown (keyCode, event)}


Leave a Reply

Your email address will not be published. Required fields are marked *