I send an email programmatically in my Android app. To do that I use an Asynctask like this:
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
//testMailButton.setEnabled(false);
processdialog = ProgressDialog.show(context, "Test mail sturen", "wachten a.u.b...");
processdialog.setCancelable(false);
}
@Override
protected Void doInBackground(Void... arg0) {
try {
properties.setProperty("emailTo", emailContactField.getText().toString());
properties.setProperty("emailFrom", emailField.getText().toString());
properties.setProperty("passWFrom", passwordField.getText().toString());
String[] temp = { properties.getProperty("emailTo").toString()};
setupMail.updateUserInfo(temp,properties.getProperty("emailFrom"), properties.getProperty("passWFrom"));
loggedIn = setupMail.sendTestMail();
loginTryDone = true;
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (processdialog != null) {
processdialog.dismiss();
testMailButton.setEnabled(true);
}
}
};
But the processDialog is never showing, until the last moment, I also tried starting it before starting the task, but that didn't work either. I am not sure why it isn't working. Can anyone help me?
Thanks