tags:

views:

44

answers:

3

When I start the SMS application using the following methods -- everything works fine up until the point where the message is sent. When I send the message -- it never navigates back to the original activity unless I press the back button. How can I start the SMS activity and then once the message is sent have the parent activity showed again?

This is how I call the SMS app with result.

String message = getMessageString();
    Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
    sendIntent.setData(Uri.parse("sms:" + number));
    sendIntent.putExtra("sms_body", message);
    startActivityForResult(sendIntent, INVITE_COMPLETED);
+1  A: 

As soon as the activity that you have started is finished, the onActivityResult() method in your first activity is called. That's why you should overwrite onActivityResult() in your first activity and handle there the activities that are finished.

Roflcoptr
I do that -- however the parent activity does not get called after the SMS is sent. It just shows the conversation thread but does not navigate back to the parent activity.
hwrdprkns
A: 

I have found out that it is not possible to return to the starting activity after posting an intent to the SMS activity.

hwrdprkns
A: 

You were wrong, perhaps you may not have noticed that you had returned to the calling activity. You have to supply a request code when calling a subactivity. INVITE_COMPLETED sounds a bit like it could represent a result code. Result codes like RESULT_OK and RESULT_CANCELED are predefined finals of the Activity class. If you use

startActivityForResult(intent, MY_REQUEST_CODE);

you can then override onActivityResult() and catch that request code (which is self defined in the starting activity) there. This is what it looks like:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == MY_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
        // do something useful
        }
    }
}
cody