title: Get URL From WebView
body: <p>I was wondering if there exits another effective way to get the URL that will load up on the WebView. My current code gives the current Url and not the one that will be loaded. </p>
  
  <p>For example if my WebView load this: <strong><code>http://stackoverflow.com</code></strong> </p>
  
  <p>After loading If I click on <strong>Questions</strong>, I would not get this url <strong>http://stackoverflow.com/questions</strong>, for some reason I would get <strong><code>http://stackoverflow.com</code></strong> </p>
  
  <p>So my question is <strong>how would you get the url that will be loading on a WebView?</strong> </p>
  
  <p>This is my code, please help! </p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      // Declaring
      WebView browser;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // Initializing
          browser = (WebView) findViewById(R.id.webView1);
  
          browser.getSettings().setJavaScriptEnabled(true);
          browser.getSettings().setLoadWithOverviewMode(true);
          browser.getSettings().setUseWideViewPort(true);
          browser.getSettings().setBuiltInZoomControls(true);
  
          // Loading
          browser.loadUrl("http://stackoverflow.com");
  
  
          browser.setWebViewClient(new WebViewClient() {
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                      view.loadUrl(url);
  
                  return true;
              }
  
              public void onLoadResource(WebView view, String url) {
  
                  //here I get the Url, but its not accurate. Sometimes it works, sometiems it doesn't 
                      Toast.makeText(getApplicationContext(), browser.getUrl(),
                              Toast.LENGTH_SHORT).show(); 
              }
  
  
          });
  
      }
  
  }
  </code></pre>