title: How do i handle closing WebView that opened in Activity Android?
body: <p>Hello i have a weird thing here, i have a list of items and i want when i click on any item, it will open an WebView which looks like this:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"  
            android:layout_width="fill_parent"  
            android:layout_height="fill_parent" android:theme="@android:style/Theme.Dialog"&gt; 
  
  &lt;WebView android:id="@+id/BrowserView"  
           android:layout_width="fill_parent"  
           android:layout_height="fill_parent"                
           android:scaleType="fitXY" /&gt;               
  </code></pre>
  
  <p>  </p>
  
  <p>here is the code i invoke the WebView</p>
  
  <pre><code>listView.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapter, View view, int position, long arg) {
              setContentView(R.layout.external_view);
  
              // load url or html
              RssItem listItem = (RssItem) listView.getItemAtPosition(position);
              webView = (WebView) findViewById(R.id.BrowserView);
  
              // set browser settings
              webView.setWebViewClient(new ExternalWebViewClient());
              webView.getSettings().setJavaScriptEnabled(true);
              webView.getSettings().setBuiltInZoomControls(true);
              webView.getSettings().setUseWideViewPort(true);
              webView.getSettings().setPluginsEnabled(true);
              webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
              webView.setInitialScale(1);
  
              try {
                  webView.loadUrl(listItem.getExternalUrl());
              } catch (Exception ex) {
                  Log.d("WEBVIEW", ex.getMessage());
              }
          }
      });
  </code></pre>
  
  <p>Here is the "ExternalWebViewClient" class</p>
  
  <pre><code>public class ExternalWebViewClient extends WebViewClient {
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
      return true;
  }
  
  @Override
  public void onPageFinished(WebView view, String url) {
      view.clearHistory();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now the question:</p>
  
  <p>How do i close it and stay in the same activity after i press the "back" button,
  here is my back button handling code:</p>
  
  <pre><code>@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (event.getAction() == KeyEvent.ACTION_DOWN) {
          switch (keyCode) {
          case KeyEvent.KEYCODE_BACK:
              if (webView.canGoBack() == true) {
                  webView.goBack();
              } else {
                  //what should i do here?????????????????                    
                  return true;
              }
          }
      }
      return false;
  }
  </code></pre>