0

我正在发送一封电子邮件,但是当用户从电子邮件撰写器返回时,我需要转到其他活动,如何完成此操作?

这是我的代码,//发送邮件

String prestartTypeString = prestartType;
String to = "juanman234@gmail.com";
String subject = "Pre-Start - "+prestartTypeString;
String message = fullName+" has sent you a Pre-Start checklist for equipment "
                  +registrationNumber+".\n" + "Please find PDF report attached.
    \n\nNeed help viewing this report\nEmail us anytime at\nhello@tiks.com.au";

Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to});

email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);

//attachment
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
                                                              "generato.pdf"));
email.putExtra(Intent.EXTRA_STREAM, uri);

//need this to prompts email client only
email.setType("message/rfc822");

startActivity(Intent.createChooser(email, "Choose an Email client :"));

setResult(RESULT_OK, email);

我检查过

startActivityForResult();

但不清楚这是否是这样做的方法,并且没有让它工作

那么当用户从电子邮件意图返回时如何触发功能呢?

谢谢

4

1 回答 1

1

使用 startActivityForResult() 启动活动;并覆盖以下方法

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
            //place your code here what you want to do when result is returned, in your  case go to different activity
}

当被调用的activity返回结果时调用该方法

于 2013-05-14T09:04:14.317 回答