Solve the problem where webview calls goBack () and returns the previous page to automatically refresh the flash white. webviewgoback
The problem is that the onKeyDown () method is rewritten to make it goBack (), but the problem is that each time you enter webview and return the original page again, there will be a flash in the middle.
I tried a lot of online methods and found that they were all nonsense.
Later, I realized that there is a cache mode in webView. How can I use different cache modes?
// Set the cache Mode
WebView. getSettings (). setCacheMode (WebSettings. LOAD_DEFAULT );
You need to change the mode to LOAD_NO_CACHE !! However, every time you have to re-request a very expensive resource, you can put it in onKeyDown () to re-write a LOAD_NO_CACHE, and only call the no-Cache mode when returning
In this way, when the previous page is returned, the Code becomes transient:
Private void initView () {webview = (WebView) findViewById (R. id. faq_wv); webview. loadUrl (url); webview. setWebViewClient (new WebViewClient () {@ Override public boolean shouldOverrideUrlLoading (WebView view, String url) {view. loadUrl (url); return true ;}}); WebSettings settings = webview. getSettings (); settings. setJavaScriptEnabled (true); settings. setCacheMode (WebSettings. LOAD_CACHE_ELSE_NETWORK);}/* rewrite the logic returned by the physical key */@ Override public boolean onKeyDown (int keyCode, KeyEvent event) {if (keyCode = KeyEvent. KEYCODE_BACK & webview. canGoBack () {// returns the webview on the previous page. getSettings (). setCacheMode (WebSettings. LOAD_NO_CACHE); webview. goBack (); return true;} return super. onKeyDown (keyCode, event );}