异步doInBackground没有被调用 [英] Async doInBackground not Getting Called

查看:110
本文介绍了异步doInBackground没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的类中,使用异步内部类函数doInBackground的结果为Hit.在调用rpi.excute并尝试通过HTTP下载的getQuestionnaireBO获取数据时,我在AndroidManifest.xml和其他配置中具有Internet权限

In below class the using async inner class function doInBackground is not getting Hit. while calling rpi.excute and then trying to get the data through getQuestionnaireBO downloaded by HTTP , I have the Internet permission in AndroidManifest.xml and other config to

public class RestApiClient {
    private final static String SERVICE_URI = "http://182.50.154.23/Dattab.Device.Rest/ServiceClass/RestDeviceService.svc";
    private QuestionnaireBO resultQuestionnaireBO ;
    public void Questionnairedownload(int QuestionnaireId ) {
        String url=SERVICE_URI+"/DownloadQuestionnaireData/"+QuestionnaireId;
        // InputStream source = retrieveStream(url);
        // Gson gson = new Gson();
        // Reader reader = new InputStreamReader(source);
        // QuestionnaireBO response = gson.fromJson(reader, QuestionnaireBO.class);
        ChildThreadQuestionnairedownload ctqd = new ChildThreadQuestionnairedownload();
        ctqd.execute(url);

        // return null ;        
    }

    public QuestionnaireBO getQuestionnaireBO() {
        return resultQuestionnaireBO;
    }


    private class ChildThreadQuestionnairedownload extends AsyncTask<String,Integer,QuestionnaireBO> {

        @Override
        protected QuestionnaireBO doInBackground(String... params) {
             String url=params[0];
             Gson gson = new Gson();
             DefaultHttpClient client = new DefaultHttpClient();                     
             HttpGet getRequest = new HttpGet(url);
             try {
                 HttpResponse getResponse = client.execute(getRequest);
                 final int statusCode = getResponse.getStatusLine().getStatusCode();

                 if(statusCode != HttpStatus.SC_OK) {
                      Log.w(getClass().getSimpleName(),
                            "Error " + statusCode + " for URL " + url);
                      return null;
                 }

                 HttpEntity getResponseEntity = getResponse.getEntity();
                 Reader reader = new InputStreamReader(getResponseEntity.getContent());
                 QuestionnaireBO response = gson.fromJson(reader, QuestionnaireBO.class);

                  return response ;
             }
             catch(IOException e){
                  e.printStackTrace();
                  return null;
             }

         }

         protected void onPostExecute(QuestionnaireBO response) {
             resultQuestionnaireBO=response;
         }

     }
}

推荐答案

我看不到doInBackground()不会被调用的任何原因.

I don't see any reason why doInBackground() won't get called.

这可能是一个转储文件,但是...您确定已建立Internet连接吗?
有时,如果您使用的是Wi-Fi,则连接可能会丢失,并且如果您使用的是3G,则可能是您花了所有钱.因此,无法访问互联网.

This probably is a dump one, but... did you make sure you have the internet connection up?
Sometimes, if you are on a wi-fi the connection may be lost, and if you are using 3G it may be that you spent all your money. So, no access to internet.

这篇关于异步doInBackground没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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