0

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

Black Magic
  • 2,706
  • 5
  • 35
  • 58

1 Answers1

0

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);
Jeffrey Klardie
  • 3,020
  • 1
  • 18
  • 23