Sending email - navigation stack disrupted

My cross-platform Xamarin Forms app (iOS and Android) needs to send an email (upon request from the user). Right now, when the user presses the appropriate button I'm calling

Page.Navigation.PushAsync(new SendEmailPage)

And then in the SendEmailPage constructor I'm using the DependencyService to send an email:

IMail mail = DependencyService.Get<IMail> ();
mail.SendMessage ("Contents");

I've implemented IMail in both Android and iOS, but looking just at the Android version:

void IMail.SendMessage (string contents)
   Intent emailIntent = new Intent(Intent.ActionSend);
   emailIntent.SetType ("message/rfc822");
   emailIntent.PutExtra (Intent.ExtraEmail, new string [] { "[email protected]" });
   emailIntent.PutExtra (Intent.ExtraSubject, "Subject");
   emailIntent.PutExtra (Intent.ExtraText, contents);
   Forms.Context.StartActivity (Intent.CreateChooser (emailIntent, "Send email"));

When I run this code, and click the appropriate button, it pops up an email "Compose" window with all the appropriate information filled in, and I can click the "send" button to send the mail. Cool!

Side Question: Am I correct in assuming there's no way to send an email "quietly" (without requiring additional user intervention)? This would not be something done maliciously, our app would only do this when the user asked to, and would certainly request the appropriate privileges if this is possible.

Main Question #1: When the "Compose" window comes up, if I click the back button in the title bar, it takes me back to my email Inbox, not back to my application. How do I invoke the email intent/activity in such a way that its back button brings the user back to my app?

Main Question #2: Instead, when the "Compose" window comes up, if I click the back button in the bottom of the screen, it does come back to my app, but tells me "Message saved as draft" which isn't what I want. I would rather have the message deleted, and then re-create it if the user hits the appropriate button again.

Sign In or Register to comment.