title: JQuery Mobile hardware back button press in android
body: <p>Can anyone give me the example of hardware back button press event listener in android device on particular page? </p>
  
  <p>I am using this code but not working. </p>
  
  <pre><code>$(document).on('pageshow', function(){
  
      document.addEventListener("backbutton", function(e){                                   
          if($.mobile.activePage.is('#dept-list-page')){  
              e.preventDefault();
              alert("back  button pressed");
              navigator.app.exitApp();        
          }else{
              history.back();
          }
       }, false);
  });
  </code></pre>
  
  <p>In Webview, I am using keydown method. </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 != null)
                  if (webView.canGoBack()) {
                      webView.goBack();
                      return true;
                  }
          }
      }
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>But many html pages generated dynamically in a single webview and I want to check this on particular page.  </p>