SMSManager and Pending Intent
<p>I have a question about an SMS app i am creating (learning purposes).</p>

<p>On sending an SMS i would like to have a toast message appear once it has been deleivered (or not)</p>

<p>Problem is once i have hit send i would like to close the activity but still have the toast message (in this case) appear giving me the info.</p>

<p>As i am new to this i am not sure how to go about this. All i have done is wait for the information to come through, set up the message then close the activity.</p>

<pre><code>private void sendSMS() {
    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), PendingIntent.FLAG_NO_CREATE);
    deliverActivity = new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS delivered", 
                    Toast.LENGTH_LONG).show();
                    finishActivity();
                    break;
                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not delivered", 
                    Toast.LENGTH_LONG).show();
                    finishActivity();
                    break;           

            }
        }
    };

    registerReceiver(deliverActivity, new IntentFilter(DELIVERED));        

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(toNo, null, toSend.getText().toString(), deliveredPI, null);

    ContentValues values = new ContentValues();
    values.put("address", toNo);
    values.put("body", toSend.getText().toString());
    this.getContentResolver().insert(Uri.parse("content://sms/sent"), values);

}

private void finishActivity() {
    unregisterReceiver(deliverActivity);
    Intent intent = new Intent();
    setResult(123, intent);
    finish();
}
</code></pre>

<p>Im sure this is possible somehow, even to pass it possibly to another activity.</p>

<p>It probably sounds a bit pedantic but it allows me to learn new ways of doing things... so if anyone can point me in the right direction that'd be great.</p>

<p>Thanks!</p>
