aguarde o processo terminar para iniciar outro processo
Quando o usuário clica no meu botão, ele executa duas funções: enviar um SMS e enviar um email.
Quando clico nesse botão, o SMS está sendo enviado e, de repente, o email escolhe a janela do cliente. Quero que a janela do seletor de cliente de e-mail seja exibida somente após a conclusão da função de envio de SMS.
Como devo mudar meu código?
Button hi= (Button) findViewById(R.id.button1);
hi.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sendsms();
sendemail();
}
private void sendemail() {
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to1});
email.putExtra(Intent.EXTRA_CC, new String[]{ to2});
email.putExtra(Intent.EXTRA_BCC, new String[]{to3});
email.putExtra(Intent.EXTRA_BCC, new String[]{to4});
email.putExtra(Intent.EXTRA_BCC, new String[]{to5});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, emailmessage);
//need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
sendsms()
{
String receipentsNumber[] = {"111","222","333","444","555"};
for (int i = 0; i < receipentsNumber.length; i++) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(receipentsNumber[i], null, message, null,
null);
System.ot.println(getApplicationContext(), "SMS Sent to" + " " + receipentsNumber[i], Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!", Toast.LENGTH_LONG)
.show();
e.printStackTrace();
}
}
}
});