title: Android - set activity result on activity closed
body: <p>To start activity for result:</p>
  
  <pre><code>Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
  startActivityForResult(intent,EVENT_DETAILS_REQUEST);
  </code></pre>
  
  <p>In my DetailsActivity, to set result and extras, that can be used in main activity:</p>
  
  <pre><code>@Override
      public void onBackPressed()
      {
          Intent resultIntent = new Intent();
          resultIntent.putExtra("isEdited",isEdited);
          setResult(RESULT_OK,resultIntent);
          finish();
      }
  </code></pre>
  
  <p>Finally, in MainActivity:</p>
  
  <pre><code>@Override
      protected void onActivityResult(int requestCode, int resultCode, @NonNull Intent data)
  {
    switch(requestCode)
    {
      ......
      case EVENT_DETAILS_REQUEST:
      boolean isEdited = data.getBooleanExtra("isEdited", false);
      .......
      break;
  
    }
  
  }
  </code></pre>
  
  <p>This is fine as long as user is using "Back" hardware (or system navbar) button to close DetailsActivity. If user tap "Back" arrow at the top of the activity to close activity, <code>onBackPressed</code> won't be called and <code>onActivityResult</code> data will be null.</p>
  
  <p>I have tried to use <code>onPause</code>, <code>onStop</code>, <code>onFinish</code> instead of <code>onBackPressed</code> to manage it working, but I'm getting <code>data</code> for <code>onActivityResult</code> always null.</p>
  
  <p>What is correct way to solve my problem?</p>