title: how to dismiss the progressbar before the loading using the back button?
body: <p>I am using the progress bar for the web view.I need to stop progress bar before the page load.I press the back button but not working in between loading.</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
           requestWindowFeature(Window.FEATURE_NO_TITLE);
           setContentView(R.layout.webview);
          mWebView = (WebView) findViewById(R.id.webview);
          mWebView.getSettings().setJavaScriptEnabled(true);
          mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
          final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
  
          progressBar =new ProgressDialog(this);
          progressBar.setCancelable(true);
          progressBar.show();
  
  
          mWebView.setWebViewClient(new WebViewClient() {
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                  Log.i("TEST", "Processing webview url click...");
                  view.loadUrl(url);
                  return true;
              }
  
              public void onPageFinished(WebView view, String url) {
                  Log.i("TEST", "Finished loading URL: " +url);
                  if (progressBar.isShowing()) {
                      progressBar.dismiss();
                  }
              }
  
              public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                  Log.e("TEST", "Error: " + description);
                  Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
                  alertDialog.setTitle("Error");
                  alertDialog.setMessage(description);
                  alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          return;
                      }
  
  
  
                  });
                  alertDialog.show();
              }
          });
          mWebView.loadUrl("http://www.google.com");
  }
  </code></pre>
  
  <p>For back button test I use this</p>
  
  <pre><code>@Override
      public boolean onKeyDown(int keyCode, KeyEvent event)  {
          if (keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() == 0) {
              Toast.makeText(getApplicationContext(),"hi", Toast.LENGTH_LONG).show();
              return true;
          }
  
          return super.onKeyDown(keyCode, event);
      }
  </code></pre>