开发者

call "shouldOverrideUrlLoading" method on webview.goBack()

I'm loading all my pages inside shouldOverrideUrlLoading method on webview (mainly to track the current page url and do some modificatio开发者_运维百科ns).

My problem is that the back button ( eg: webview.goback() method ) bypasses the above function.

Is there any way i can explicitly call both the goback() and shouldOverrideUrlLoading() methods.

public boolean shouldOverrideUrlLoading(WebView view, String url){
//get current url and do some modifications to html}

public boolean onKeyDown(int keyCode, KeyEvent event) {
     if ((keyCode == KeyEvent.KEYCODE_BACK) && web1.canGoBack()) {
         webview.goBack();  
         return true;
      }
      return super.onKeyDown(keyCode, event);
}


Looking at your code seems like once the shouldOverrideUrlLoading method is called based on some logic for a specific URL Action you need the Webview go back method. I would suggest you to use the following method inside the activity:

@Override
public void onBackPressed() {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && web1.canGoBack()) {
        webview.goBack();
    } else {
        super.onBackPressed();
    }
}

which does exactly the same as onKeypressed. (Used onBackPressed instead of onKeypressed but write this code inside the Activity class but not inside the custom WebViewClient.

Call the onBackPressed() inside your shouldOverrideUrlLoading. Try this, should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜