title: Returning intent result when Activity is closed by back button
body: <p>I start a new <code>Activity</code> from the original <code>Activity</code> with <code>startActivityForResult(intent, requestCode)</code>. I want to return data to the original <code>Activity</code> when the user presses the back button, so when returns to the original <code>Activity</code>. I tried two methods:</p>
  
  <ul>
  <li><p>overriding <code>onBackPressed()</code>:</p>
  
  <pre><code>@Override
  public void onBackPressed() {
      super.onBackPressed();
  
      Intent intent = new Intent();
      intent.putIntegerArrayListExtra(SELECTION_LIST, selected);
      setResult(RESULT_OK, intent);
  }
  </code></pre></li>
  <li><p>overriding <code>onPause()</code>:</p>
  
  <pre><code>@Override
  protected void onPause() {
      super.onPause();
  
      Intent intent = new Intent();
      intent.putIntegerArrayListExtra(SELECTION_LIST, selected);
      setResult(RESULT_OK, intent);
  }
  </code></pre></li>
  </ul>
  
  <p>Unfortunately, none of them worked (<code>resultCode</code> is not <code>RESULT_OK</code> in <code>onActivityResult()</code>). What's the proper way to do this? Thanks!</p>