jublikon jublikon - 1 year ago 102
Android Question

returnActivity events when calling startActivity method

I have an

and I start an appliction chooser with

Question: How can I wait with the finishing the parent activity until the user has selected a preferred mail app?

Uri uri = Uri.parse("mailto:" + "someone@mail.com")
.appendQueryParameter("subject", "subject")
.appendQueryParameter("body", "body")

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(Intent.createChooser(emailIntent, "chooser Title"));


Answer Source

As stated in this post, you could use IntentPicker instead of IntentChooser

Intent intentPick = new Intent();
intentPick.putExtra(Intent.EXTRA_TITLE, "Launch using");
intentPick.putExtra(Intent.EXTRA_INTENT, emailIntent);
this.startActivityForResult(intentPick, REQUEST_CODE_MY_PICK);
// You have just started a picker activity, 

Then you can listen for the result of the intent pick by adding the following callback method in your activity:

protected void onActivityResult(int requestCode, int resultCode, Intent data)
    if (requestCode == REQUEST_CODE_MY_PICK) {
         // start the activity the user picked from the list

         //you can finish() your activity here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download