1

I have an Activity and I start an appliction chooser with startActivity.

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")
                .buildUpon()
                .appendQueryParameter("subject", "subject")
                .appendQueryParameter("body", "body")
                .build();

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

 finish();
jublikon
  • 3,427
  • 10
  • 44
  • 82

1 Answers1

2

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

Intent intentPick = new Intent();
intentPick.setAction(Intent.ACTION_PICK_ACTIVITY);
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:

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

         //you can finish() your activity here
    }
}
Community
  • 1
  • 1
Yves Delerm
  • 785
  • 4
  • 10
  • How can I avoid the issue for onActivityResult: "Annotations are not allowed here" ? – jublikon Nov 25 '16 at 09:56
  • I guess you added the onActivityResult in a wrong place, for instance in another method. It should be directly in your activity class – Yves Delerm Nov 25 '16 at 10:02