我在我的 Android 应用程序中以编程方式发送电子邮件。为此,我使用这样的 Asynctask:
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);
}
}
};
但是 processDialog 从未显示,直到最后一刻,我也尝试在开始任务之前启动它,但这也不起作用。我不确定为什么它不起作用。谁能帮我?
谢谢