我有一个Activity,然后用startActivity启动应用程序选择器。
问题:如何等待完成父活动,直到用户选择了首选的邮件应用程序?

 Uri uri = Uri.parse("mailto:" + "[email protected]")
                .buildUpon()
                .appendQueryParameter("subject", "subject")
                .appendQueryParameter("body", "body")
                .build();

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

 finish();

最佳答案

in this post所述,您可以使用IntentPicker代替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,


然后,您可以通过在活动中添加以下回调方法来侦听意图选择的结果:

@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
    }
}

10-06 06:33