title: Overriding Back Button Action in Activity
body: <p>I have just overide my back button in my code like this</p>
  
  <pre><code>        @Override
          public boolean onKeyDown(int keyCode, KeyEvent event) {
              if (keyCode == KeyEvent.KEYCODE_BACK) {
  
                  return true;
              }
              return super.onKeyDown(keyCode, event);
          }
  
          @Override
          public boolean onKeyUp(int keyCode, KeyEvent event)
            {
  
                   {
                         startActivity(new  Intent(context, MainDialog.class));
                         finish();
  
                  return true;
              }
              return super.onKeyUp(keyCode, event);
          }
  </code></pre>
  
  <p>Now I am facing a weird problem,
  I have a edit text on the current Activity.
  At the time of editing when I am trying to close the virtual keyboard by pressing the back
  button .
  My Application finishes...
  But I just want to close the keyboard not the Avtivity..
  Any suggestion to solve my issue..?</p>
  
  <p>Thanks in advance,
  Tanmay </p>
  
  <hr>
  
  <pre><code>I have tried both 
  
         @Override
      public boolean onKeyUp(int keyCode, KeyEvent event) 
          {
          if (keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; event.getRepeatCount() == 0) {
  
                 startActivity(new  Intent(context, MainDialog.class));
                 finish();
                 return true;
          }
          return super.onKeyUp(keyCode, event);
      }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>        @Override
      public boolean onKeyUp(int keyCode, KeyEvent event) 
          {
          if (keyCode == KeyEvent.KEYCODE_BACK ) {
  
                 startActivity(new  Intent(context, MainDialog.class));
                 finish();
                 return true;
          }
          return super.onKeyUp(keyCode, event);
      }
  </code></pre>
  
  <p>But no result.
  Any suggestion!!</p>