title: android notify when startActivity intent has completed?
body: <p>I need to be able to tell when a spawned activity (via an intent) has completed, how would I do so?</p>
  
  <p>This is what I have:</p>
  
  <pre><code>    alertDialog.setButton2("Text", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              String uri = "smsto:" + "";
              Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
              intent.putExtra("sms_body", PASSWORD_GENERATOR
                      .generatePasswordForSeed(seedText, hourToUse));
              intent.putExtra("compose_mode", true);
  
              // -- open the text message activity
              startActivity(intent);
  
              // -- I need to reset the calling activity now, but AFTER the text message activity has completed. Right now the SMS closes right away as I have no wait in...
              finish();
              startActivity(getIntent());
          }
      });
  </code></pre>
  
  <h2><strong>EDIT #1</strong></h2>
  
  <p>Per the suggestions below, I've made some modifications. Now, however, the launched SMS activity just "sits there" once the text is sent. I can't figure out how to get it to return to the calling activity. This is what I have:</p>
  
  <pre><code>alertDialog.setButton2("Text", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  String uri = "smsto:" + "";
                  Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
                  intent.putExtra("sms_body", PASSWORD_GENERATOR
                          .generatePasswordForSeed(seedText, hourToUse));
                  intent.putExtra("compose_mode", true);
  
                  startActivityForResult(intent, Activity.RESULT_OK);
  
                  registerReceiver(new BroadcastReceiver() {
                      @Override
                      public void onReceive(Context context, Intent intent) {
                          finish();
                          startActivity(getIntent());
                      }
  
                  }, new IntentFilter("SMS_SENT"));
  
                  ContentResolver contentResolver = getContentResolver();
                  Handler handler = new Handler();
  
                  contentResolver.registerContentObserver(Uri
                          .parse("content://sms"), true, new ContentObserver(
                          handler) {
  
                      @Override
                      public boolean deliverSelfNotifications() {
                          setResult(Activity.RESULT_OK);
                          finish();
  
                          return super.deliverSelfNotifications();
                      }
  
                      @Override
                      public void onChange(boolean selfChange) {
                          super.onChange(selfChange);
  
                          setResult(Activity.RESULT_OK);
                          finish();
                      }
                  });
              }
          });
  
          alertDialog.show();
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          finish();
          startActivity(getIntent());
      }
  </code></pre>