title: How to set a new listener for back key?
body: <p>I want that when the user is pressing the back button on the keyboard of the android, the activity will close (and the preview activity will be shown) and beside that i would like the app to do another thing.<br>
  When I tried to do by the Instructions here: 
  <a href="https://stackoverflow.com/questions/2592037/is-there-a-default-back-keyon-device-listener-in-android">is there a default back key(on device) listener in android?</a> when I'm pressing the back button, the activity is close and open again. When I'm pressing the back button again the activity is close and the preview activity is opend.<br>
  Anybody knows why? Does anybody have another idea for this?  </p>
  
  <p>This is some of the codes i tried:
  Option One:</p>
  
  <pre><code>@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if(keyCode == KeyEvent.KEYCODE_BACK){
          //Show the dialog and get the response
          ArrayList&lt;User&gt; lstChosenContacts = new ArrayList&lt;User&gt;();
          for(int i = 0; i &lt; this.lstContacts.size(); i++) {
              if(this.lstContacts.get(i).getIsChecked()) {
                  lstChosenContacts.add(this.lstContacts.get(i).getUserContact());
              }
          }
          Intent data = new Intent();
          data.putExtra("lstChosenContacts", lstChosenContacts);
       setResult(RESULT_OK,data);
  
      }
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>Option 2:</p>
  
  <pre><code>@Override
  public void onBackPressed() {
      ArrayList&lt;User&gt; lstChosenContacts = new ArrayList&lt;User&gt;();
      for(int i = 0; i &lt; this.lstContacts.size(); i++) {
          if(this.lstContacts.get(i).getIsChecked()) {
              lstChosenContacts.add(this.lstContacts.get(i).getUserContact());
          }
      }
      Intent data = new Intent();
      data.putExtra("lstChosenContacts", lstChosenContacts);
       setResult(RESULT_OK,data);
      super.onBackPressed();
  }
  </code></pre>
  
  <p>Thanks!</p>