AsyncTask的:使用Web服务和放大器;线程 [英] AsyncTask: Using web services & threads

查看:192
本文介绍了AsyncTask的:使用Web服务和放大器;线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的按钮的AsyncTask点击刷新屏幕。以下为BTN点击发生的事件序列


  1. 进度对话框显示出来

  2. 的doInBackground被调用,线程初始化它调用的Web服务。 Web服务获取/上传数据。一旦Web服务被称为合格/不合格标志设置。

我的问题是onPostExecute不会被调用,因此屏幕刷新永远不会。
其次由当时的数据下载和Web服务设置我的code已经回车语句在doInBackground国旗。

问题是如何在我的AsyncTask停止执行,使Web服务完成下载/上传的数据并最终执行onPostexecute。

FYI
我也得到日食以下警告


  

从方法onPostExecute(布尔)
  方式
  Screen.ConnectWebService是
  从来没有在本地使用


 私有类ConnectWebService扩展的AsyncTask<太虚,太虚,布尔>
        {
            私人最终ProgressDialog PD =新ProgressDialog(但屏幕);            在preExecute保护无效(){
                pd.show(但屏幕,同步,正在同步,真,假);
            }
            保护布尔doInBackground(虚空......未使用){                如果(SyncInProgress == FALSE)
                {                    CallWSThread(); //创建一个线程这就要求网络服务
                }
                        Log.d(doInBackground,doInBackground);
                返回SYNCSTATUS;
            }            保护无效onPostExecute(布尔结果)
            {                pd.dismiss();
                如果(结果== true)而drawRadioButtons();                 返回null;
            }        }


解决方案

它应该是:

 保护无效onPostExecute(布尔结果)

I am using AsyncTask on button click to refresh the screen. Following is the sequence of events that happen on btn click

  1. progress dialog shows up
  2. The doInBackground is called and thread is initialized which calls a web service. The web service fetches/uploads data. A pass/fail flag is set once the web service is called.

My problem is the onPostExecute is never called and therefore the screen is never refreshed. And secondly by the time the data is downloaded and the web service sets the flag my code has already hit return stmt in doInBackground.

Question is how do i stop execution in my asynctask so that the web service is done downloading/uploading the data and finally execute onPostexecute.

FYI I also get the following warning in eclipse

The method onPostExecute(boolean) from the type Screen.ConnectWebService is never used locally

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

        }

解决方案

It should be:

protected Void onPostExecute(Boolean result)

这篇关于AsyncTask的:使用Web服务和放大器;线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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