title: Can onBackPressed set and return an intent result?
body: <p>My MainActivity can call two different activities (a &amp; b).  Activity A is called as follows:</p>
  
  <pre><code>   private View.OnLongClickListener alc = new View.OnLongClickListener(){
      public boolean onLongClick(View v) {
          Intent j = new Intent(MainActivity.this,AActivity.class);
          startActivityForResult(j, 1);
          return true;
      }
  };
  </code></pre>
  
  <p>The A activity has two buttons, one to SAVE and one to CANCEL.  The SAVE returns a result...</p>
  
  <pre><code>    public void onClick(View v) {
      switch(v.getId()){
          case R.id.btnSave:
              Intent returnIntent = new Intent();
              setResult(RESULT_OK,returnIntent);
              finish();
              break;
          case R.id.btnCxl:
              finish();
              break;
      }
  }
  </code></pre>
  
  <p>This works PERFECTLY!!</p>
  
  <p>I want the similar return for Activity B.  I modified it's Intent call as follows...</p>
  
  <pre><code>private View.OnClickListener ac = new View.OnClickListener() {
      public void onClick(View v) {
          Intent j = new Intent(MainActivity.this,BActivity.class);
          startActivityForResult(j, 1);
      }
  };
  </code></pre>
  
  <p>In the B activity, I don't have a SAVE button to "catch".   After browsing, I see the <code>onBackPressed()</code> is available because that is how I am leaving this activity usually.   I read I should be able to put the result code in there elsewhere online..</p>
  
  <pre><code>public void onBackPressed() {
      super.onBackPressed();
      Intent returnIntent = new Intent();
      setResult(RESULT_OK, returnIntent);
      }
  </code></pre>
  
  <p>Putting in some <code>Log.i</code> calls in my <code>onActivityResult</code>in the MainActivity...</p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      Log.i("MYLOG","In Result");
      if (requestCode==1) {
          Log.i("MYLOG","In Result 1");
          if (resultCode == RESULT_OK) {
              Log.i("MYLOG","In Result 1 OK");
              // Do some data processing and display here!!
          }
      }
  }
  </code></pre>
  
  <p>As mentioned, A activity, works fine... hits all three <code>Log.i</code> statements.    B activity hits first two, but never hits 3rd.</p>
  
  <p>What am I missing here?</p>
  
  <p>Thanks Pete</p>