Android的AsyncTask的GUI滞留 [英] Android AsyncTask GUI Stuck

查看:165
本文介绍了Android的AsyncTask的GUI滞留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用程序编程发送电子邮件。要做到这一点我使用的AsyncTask是这样的:

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);
                }
            }

        };

但processDialog永远不会显示,直到最后一刻,我也试过在开始任务之前启动它,但是这也不能工作。我不知道为什么它不工作。谁能帮我?

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?

感谢

推荐答案

我想你想的ProgressDialog不确定的(未测负载量,因为你不知道进展如何)。您可以使用此构造:

I think you want to make the ProgressDialog indeterminate (loading amount not measured, because you don't know what the progress is). You can use this constructor:

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

而你的情况就会是这样的:

Which in your case will look like:

processdialog = ProgressDialog.show(context, 
    "Test mail sturen", 
    "wachten a.u.b...", 
    true, false);

这篇关于Android的AsyncTask的GUI滞留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆