webview opens utorrent

hello friends,
i am using webview in my app and using local html pages(from the assets folder).
generally it is working fine, but in devices with utorrent installed, utorrent app is being open, i am getting some bad ratings because of this.
i found a solution to this -

wv.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});

but this is giving problem that history back feature takes two pages back.
so pls help how to do it…
thank you.

U can set “back button listener”

@Override
public void onBackPressed() {
//what r u want to do when back button pressed?
}

are you using javascript history.back() to navigate back or the webview’s .goBack() ?

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there’s history
if ((keyCode == KeyEvent.KEYCODE_BACK) && wv.canGoBack()) {
wv.goBack();
return(true);

    }
    
    return super.onKeyDown(keyCode, event);

}

i am using this…will this work fine with the above code for utorrent problem?

That’s very strange then because I use this exact code and the goBack() never skips a page. However, using javascript redirects in your html WILL screw it all up.

There is a solution that should work every time using onPageFinished() and keeping a list of visited urls, although you shouldn’t have to. The code is here:

webkit - Get last loaded url of webview without doing a webView.goBack() in Android - Stack Overflow

Place the onPageFinished function directly below your shouldOverrideUrlLoading() function

However, if the history url is missing because a javascript redirect was used then this won’t work.