2012-02-07 66 views
0
public class IdAsync extends AsyncTask<String, Void, Void> { 

AlertDialog alertDialog = new AlertDialog.Builder(MainClass.this).create(); 

    protected Void doInBackground(String... params) { 
     . 
     . 
     alertDialog.setTitle("Reset..."); 
      alertDialog.setMessage("R u sure?"); 
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 

        //here you can add functions 

       } }); 

    alertDialog.show(); 
     . 
    .} 

這給出了運行時錯誤 發生錯誤E/AndroidRuntime(16606):在android.app.Dialog.show(Dialog.java:241)AlertBox - 執行doInBackground()

回答

1

您應該在AsyncTask的onPostExecute,onPreExecute或onProgressUpdate方法中執行對話框來更新UI。 不在背後。

相關問題