发送电子邮件返回主屏幕

时间:2013-04-10 03:26:11

标签: android email android-intent android-activity

所以,我有这段代码来创建电子邮件Intent,以便我的用户可以发送支持邮件。

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"username@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "The subject");
i.putExtra(Intent.EXTRA_TEXT, "The body");
startActivity(Intent.createChooser(i, "Send email"));

使用该代码,它会打开一个对话框,我将选择使用哪个应用程序发送电子邮件。当我按下Back button时,它会返回Home screen,如果我点击其他地方关闭对话框。当我选择一个应用程序,例如Gmail时,它会打开Gmail(我现在可以发送电子邮件),但是当我按下发送时它也会回到Home screen,如果我按下Back button

现在,我的问题是如何返回上一个Activity按下我按Back button,如果我想取消发送邮件?当我要取消它时也用于对话框。

1 个答案:

答案 0 :(得分:1)

尝试使用电子邮件,过滤方式更好:

Intent feedback = new Intent(Intent.ACTION_VIEW);
            Uri data = Uri.parse("mailto:?subject=" + "SUBJECT"
                    + "&body=" + "BODY" + "&to="
                    + "EMAILADRESS");
            feedback.setData(data);
            startActivity(feedback);

这对我来说很棒