title: onKeyDown() or onBackPressed()
body: <p>I want to implement the back button functionality in my application. In application whenever  I'm clicking on back button in middle my control is going to login page directly, so can someone tell me where to override <code>onKeyDown()</code> or <code>onBackPressed()</code> methods?</p>
  
  <pre><code>public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          Log.e("back key pressed","Back key pressed");
          return true;
      }
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>because I'm writing this inside onCreate and outside onCreate also, but it's not working ......</p>