1
I’m trying to make the Android app show an "email sent successfully" message after an email, which is linked to the action of the send button, be sent correctly. I tried to show a Toast, but it shows before the email is sent.
Follows the code
void enviar_Click(object sender, EventArgs e)
{
try
{
RadioButton rdbgrupo1 = FindViewById<RadioButton>(rdgconquiste.CheckedRadioButtonId);
RadioButton rdbgrupo2 = FindViewById<RadioButton>(rdgcrie.CheckedRadioButtonId);
RadioButton rdbgrupo3 = FindViewById<RadioButton>(rdgviva.CheckedRadioButtonId);
RadioButton rdbgrupo4 = FindViewById<RadioButton>(rdgentregue.CheckedRadioButtonId);
int RadioGroupIsChecked(RadioGroup radioGroup)
{
//-1 means empty selection
return radioGroup.CheckedRadioButtonId;
}
//When user doesn't check a radio button, show a Toast
if (RadioGroupIsChecked(rdgconquiste) == -1 || RadioGroupIsChecked(rdgcrie) == -1 || RadioGroupIsChecked(rdgviva) == -1 || RadioGroupIsChecked(rdgentregue) == -1)
{
string excecao = "Ao menos um botão de cada campo deve ser selecionado e o comentário deve ser preenchido";
Toast.MakeText(this, excecao, ToastLength.Long).Show();
}
else
{
String emailescolhido = spinner.SelectedItem.ToString();
String campocomentario = comentário.Text;
var email = new Intent(Android.Content.Intent.ActionSend);
//send to
email.PutExtra(Android.Content.Intent.ExtraEmail,
new string[] { "" + emailescolhido });
//cc to
email.PutExtra(Android.Content.Intent.ExtraCc,
new string[] { "" });
//subject
email.PutExtra(Android.Content.Intent.ExtraSubject, "SABIA QUE VOCÊ FOI RECONHECIDO?");
//content
email.PutExtra(Android.Content.Intent.ExtraText,
"Você foi reconhecido pelo(s) valor(es) de: " + rdbgrupo1.Text + " , " + rdbgrupo2.Text + " , " + rdbgrupo3.Text + " e " + rdbgrupo4.Text + " " + " " + campocomentario);
email.SetType("message/rfc822");
StartActivity(email);
}
string enviado = "Email enviado com sucesso";
RunOnUiThread(() => Toast.MakeText(ApplicationContext, enviado, ToastLength.Long).Show());
}
}
https://forums.xamarin.com/discussion/81278/how-to-handle-the-result-of-startactivityforresult-in-forms
– Rovann Linhalis