调用startActivity方法时的returnActivity事件

时间:2016-11-25 09:27:39

标签: android android-intent android-activity

我有一个Activity,我启动了startActivity的应用选择器。

问题:在用户选择首选邮件应用程序之前,我如何等待完成父活动?

 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();

1 个答案:

答案 0 :(得分:2)

如前所述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
    }
}