AsyncTask:使用Web服务&线程

时间:2011-05-06 18:25:28

标签: android multithreading web-services android-asynctask

我在点击按钮时使用AsyncTask来刷新屏幕。以下是btn点击

上发生的事件序列
  1. 进度对话框显示
  2. 调用doInBackground并初始化线程,调用Web服务。 Web服务获取/上载数据。调用Web服务后,将设置通过/失败标志。
  3. 我的问题是从不调用onPostExecute,因此屏幕永远不会刷新。 其次,在下载数据并且Web服务设置标志时,我的代码已经在doInBackground中命中了返回stmt。

    问题是如何在asynctask中停止执行,以便Web服务完成下载/上传数据并最终执行onPostexecute。

    FYI 我也在eclipse中收到以下警告

      

    方法onPostExecute(boolean)来自   类型   Screen.ConnectWebService是   从未在本地使用

    private class ConnectWebService extends AsyncTask <Void, Void, Boolean>
            {
                private final ProgressDialog pd = new ProgressDialog(screen.this);
    
                protected void onPreExecute() {
                    pd.show(Screen.this, "Sync", "Sync in progress",true,false);
                }
    
    
                protected Boolean doInBackground(Void... unused) {
    
                    if (SyncInProgress == false)
                    {
    
                        CallWSThread();//creates thread which  calls web service
                    }
                            Log.d("doInBackground","doInBackground");
                    return SyncStatus;
                }
    
                protected Void onPostExecute(boolean result)
                {   
    
                    pd.dismiss();
                    if (result==true) drawRadioButtons();
    
                     return null;
                }
    
            }
    

2 个答案:

答案 0 :(得分:4)

应该是:

protected Void onPostExecute(Boolean result)

答案 1 :(得分:1)

正如djg所说,你的方法声明中有一个拼写错误。当您从超类实现方法时,可以通过使用注释@Override来避免这些错误。