0

我在我的 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 从未显示,直到最后一刻,我也尝试在开始任务之前启动它,但这也不起作用。我不确定为什么它不起作用。谁能帮我?

谢谢

4

1 回答 1

0

我认为您想让 ProgressDialog 不确定(未测量加载量,因为您不知道进度是多少)。您可以使用此构造函数:

public static ProgressDialog show (Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable)

在您的情况下,它看起来像:

processdialog = ProgressDialog.show(context, 
    "Test mail sturen", 
    "wachten a.u.b...", 
    true, false);
于 2013-10-24T11:39:23.280 回答