Home > Mobile >  Please explain bosses Android webview goBack () and goBackOrForward difference between (1)
Please explain bosses Android webview goBack () and goBackOrForward difference between (1)

Time:11-29

As title, I met a situation, if a web page is on the computer, mobile phone to access a web page will automatically jump to b (b fit the phone side), the resulting webview cannot return to the previous page, will keep loading a - & gt; B this process, but I carried on the judgment, if b website and I clicked on the return key (return key is using a webview. GoBack () method) at the same site, after is executed webview. GoBackOrForward (2), but - 2 unexpectedly many jumps a page, so finally the webview. GoBackOrForward (1) normal use, but I click the back button of the webview. GoBack () method into the webview. GoBackOrForward (1), to a - & gt; B here still can't return to normal

Below is click on the return key processing code
 
WebView. SetOnKeyListener (new View. OnKeyListener () {
@ Override
Public Boolean onKey (View v, int keyCode, KeyEvent event) {
If (event. GetAction ()==KeyEvent. ACTION_DOWN) {
//can press the return key operation and back page
If (keyCode==KeyEvent. KEYCODE_BACK & amp; & WebView. CanGoBack ()) {
//back
/* *
* get back path, if the previous path==portal home page, then jump straight to the home page (prevent't return), or directly to return to previous page
* if it is a heavy load for the mobile computer page page lead to can't return, after the judgment directly before returning the page
*/
WebBackForwardList backForwardList=webView. CopyBackForwardList ();
If (backForwardList!=null & amp; & BackForwardList. GetSize ()!=0) {
//the current page in the history of the positions of the queue
Int currentIndex=backForwardList. GetCurrentIndex ();
WebHistoryItem historyItem.=backForwardList getItemAtIndex (currentIndex - 1);
If (historyItem!=null) {
String backPageUrl=historyItem. GetUrl ();
If (backPageUrl. Equals (" home address ")) {
The v (" record: ", backPageUrl);
WebView. LoadUrl (" home address ");
WebView. PostDelayed (new Runnable ()
{
@ Override
Public void the run ()
{
WebView. ClearHistory ();
}
}, 1000);
} else {
String f_url=webView. GetUrl ();
WebView. GoBack ();
String b_url=webView. GetUrl ();
{if (f_url. Equals (b_url))
WebView. GoBackOrForward (1);
}
}
}
}
} else {
OnBackPressed ();//double return to exit the app
}
}
return true;
}
});
  • Related