Android AsyncTask GUI Stuck

时间:2013-10-24 10:04:45

标签: android email android-asynctask

我在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永远不会显示,直到最后一刻,我也尝试在启动任务之前启动它,但这也没有用。我不确定为什么它不起作用。任何人都可以帮助我吗?

由于

1 个答案:

答案 0 :(得分: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);
相关问题