title: Android - onBackPressed() not working
body: <p>I have an application building against Android 2.1 and I want to override the back button.</p>
  
  <p>I have followed the example here:</p>
  
  <p><a href="http://android-developers.blogspot.com/2009_12_01_archive.html" rel="noreferrer">http://android-developers.blogspot.com/2009_12_01_archive.html</a></p>
  
  <p>And my code is as follows:</p>
  
  <hr>
  
  <pre><code>    @Override
      public boolean onKeyDown(int keyCode, KeyEvent event)  {
          if (Integer.parseInt(android.os.Build.VERSION.SDK) &lt; 5
                  &amp;&amp; keyCode == KeyEvent.KEYCODE_BACK
                  &amp;&amp; event.getRepeatCount() == 0) {
              Log.d("CDA", "onKeyDown Called");
              onBackPressed();
          }
  
          return true;
      }
  
      @Override
      public void onBackPressed() {
      Log.d("CDA", "onBackPressed Called");
          Intent setIntent = new Intent(Intent.ACTION_MAIN);
          setIntent.addCategory(Intent.CATEGORY_HOME);
          setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(setIntent); 
  
          return;
      }   
  </code></pre>
  
  <hr>
  
  <p>It works on pre 2.x devices but doesn't work on a Hero with 2.1 update-1 and a Nexus One with 2.2.</p>
  
  <p>Is there somwthing I am missing from the example? Or can anyone point out why it isn't working?</p>
  
  <p>I dont even get the button pressed in the logcat.</p>