2013-10-24 62 views
0

我在我的Android应用程序中以编程方式发送电子邮件。要做到这一点我用这样一个的AsyncTask:Android AsyncTask GUI卡住

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

感谢

+0

尝试processdialog =新ProgressDialog(YourActivity.this);代替。 –

+0

你的意思是_“直到最后一刻”_ –

+0

发布你的doinBackground和onPostExecute方法。 –

回答

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