Reputation: 16168
I'm sending an email, but I need to go to a different activity when the user comes back from the email composer, how to accomplish this?
here my code, //send mail
String prestartTypeString = prestartType;
String to = "[email protected]";
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\[email protected]";
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);
I have checked
startActivityForResult();
but dont have clear if this is the way to do it, and have not make it work
so how to trigger a function when the user comes back from the email intent?
thanks
Upvotes: 0
Views: 1554
Reputation: 916
start the activity with startActivityForResult(); and override the following method
@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
}
This method is invoked when the called activity returns the result
Upvotes: 1