0

Let's say be navigate through site1.com site2.com/a.html then it redirects to site2.com/b.html automatically. if you press back button on webview in an app, it tries to go back to site2.com/a.html which redirect you to site2.com/b.html which is not desirable. If you try this on chrome browser you go back to site1.com.

How can this achieve programmatically?

Baris
  • 797
  • 2
  • 10
  • 15

1 Answers1

0

You may use this answer's approach https://stackoverflow.com/a/6077173/2879783

And If I didn't got you wrong, you may implement the following:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
        case KeyEvent.KEYCODE_BACK:
            String webUrl = myWebView.getUrl();
            if(webUrl.equals("site2.com/a.html")){
                myWebView.load("site1.com");
            }else{
                finish();
            }
            return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}
Community
  • 1
  • 1
  • site1.com etc is just sample. I could not use code for the urls. If there is redirect your suggestion is not solution for the problem that I described above. Thanks anyway. – Baris Nov 14 '14 at 10:02