我有一个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();
答案 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
}
}