2

Works:

mWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl("file:///android_asset/www/css-js/app.css");
        return true;
    }
});

Doesn't Work:

mWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl("http://yahoo.com");
        return true;
    }
});
Nuri Hodges
  • 868
  • 6
  • 13
  • Try [this post](http://stackoverflow.com/questions/3845938/android-how-to-open-new-browser-from-webviewclient). Could be that you need to set a browser intent – Kyle May 24 '11 at 19:05
  • Did the answer below solve your problem? If not, please give details. – Sven Viking May 28 '11 at 09:09

1 Answers1

2

The problem is just that an infinite loop is being created. It re-overrides the new loadUrl each time. For example, this works without problems:

public boolean shouldOverrideUrlLoading(WebView view, String url) 
{
    if(!url.toLowerCase().contains("yahoo.com"))
    {
        view.loadUrl("http://yahoo.com");
        return true;
    }
    return false;
}

Note that simply saving the last override URL and comparing with if(!url.equals(lastOverrideUrl)) will not work in this case (and many others), as the URL is automatically changed from "http://yahoo.com" to "http://www.yahoo.com/".

Sven Viking
  • 2,660
  • 21
  • 34