android Action_send意图如何知道一旦发送电子邮件以关闭当前活动?

时间:2013-07-22 17:47:17

标签: android

我有一个action_send意图,允许用户发送电子邮件,但是当他们完成后,我想将它们返回到与发送电子邮件时不同的活动。 我的意图代码如下:

public void sendEmail(){
    String path = Environment.getExternalStorageDirectory().toString() + "/" + "screenshots/";
    String target_filename = "CheeseNav.jpg";
    File externalFile = new File(path, target_filename);

            Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
    i.putExtra(Intent.EXTRA_SUBJECT, "Email sent from android app");
    i.putExtra(Intent.EXTRA_TEXT, "");
    Uri sendUri = Uri.fromFile(externalFile);
    i.putExtra(Intent.EXTRA_STREAM, sendUri);

    try{
        startActivity(Intent.createChooser(i,  "Send mail..."));
    } catch(android.content.ActivityNotFoundException ex){
        Toast.makeText(ScreenViewer.this, "There are no email clients installed.",
                Toast.LENGTH_SHORT).show();
    }

}

1 个答案:

答案 0 :(得分:0)

如果您想要在发送电子邮件的过程之前返回某些活动,您必须使用标记制作意图以清除活动的顶部。您可以使用Intent.FLAG_ACTIVITY_CLEAR_TOP

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);