title: Need to Show Progress Dialog on WebView Initial Page Load
body: <p>I'm working on a simple android app that loads a single website using the Android Level 8 api.  I'm coding with Java in Eclipse.  I've been able to show a ProgressDialog when the user clicks a link on a webpage in the application which is working fine.</p>
  
  <p>The issue, however, is when the app is loaded for the first time and the very first webpage is loaded.  The web pages take awhile and it simply shows a blank white screen while the first page is loading and starting to show elements (using the Android Emulator for programming).  I'd like to display the same ProgressDialog indicator during this first page load, but have been unsuccessful in my attempts.</p>
  
  <p>Here is my code below.</p>
  
  <pre><code>package com.TestWebView;
  
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Message;
  import android.webkit.WebView;
  import  android.webkit.WebViewClient;
  
  
  public class TestWebView extends Activity {
  
  
      /** Called when the activity is first created. */
  
  
      @Override
  public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
  
          WebView engine = (WebView) findViewById(R.id.web_engine);
  
          WebViewClient myWebClient = new  WebViewClient()
          {
              ProgressDialog pd = null;
  
              // Override page so it's load on my view only
              @Override
              public boolean shouldOverrideUrlLoading(WebView  view, String  url)
              {
                  /*view.loadUrl(url);
                  return true;*/
  
                  //start the progress dialog
                  pd = ProgressDialog.show(TestWebView.this, "", "Loading...");
  
  
                   if (url.contains("maps.google.com") == true)
                   {
                      // Load new URL Don't override URL Link
                       Uri uri = Uri.parse(url);
                       Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                       startActivity(intent);
                      return true;
                   }
                   return false;
              }
  
              @Override
              public void onPageFinished(WebView view, String url){
                  pdHandler p = new pdHandler();
                  p.sendEmptyMessage(0);
              }
  
              class pdHandler extends Handler {
                  @Override
                  public void handleMessage(Message msg) {
                    if(pd != null)
                    {
                    pd.dismiss();
                    pd = null;
                    }
                  }
              }
  
          };
  
  
          engine.getSettings().setJavaScriptEnabled(true);
          engine.getSettings().setSupportZoom(true);
          engine.getSettings().setBuiltInZoomControls(true);
          engine.setWebViewClient(myWebClient);
          engine.loadUrl("http://www.amazon.com/gp/aw/h.html");
  
      }
  
  
  }
  </code></pre>
  
  <p>Any guidance is appreciated.</p>
  
  <p>Thank you.</p>