onPostExecute从未在android中调用过

时间:2017-02-17 07:06:00

标签: android android-asynctask

这是我的扩展AsyncTask的类,当我尝试运行这个类时,我的OnPostExecute从未被调用过,我不知道为什么,请提出建议,万分感谢。

public  class loadingdata extends AsyncTask<String, String, String> {
        Context mContext;
    public loadingdata(Context context) {
        super();
        mContext = context;
    }

    @Override
    protected String doInBackground(String... params) {
        ToWebservice toWebservice = new ToWebservice(ScanPage.this);
        toWebservice.postDataHdr(Branch, DocNo, Status, Date);
        toWebservice.postDataDtl(DocNo);
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        if (result != null) {
            waitDialog.cancel();

        } else {
        }
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        waitDialog = ProgressDialog.show(mContext, "Working", "Please Wait", true, true);
        waitDialog.setCanceledOnTouchOutside(false);

    }

}

4 个答案:

答案 0 :(得分:2)

为什么要返回null?

  

返回null; //问题在这里

<强> doInBackground

  

此方法包含需要执行的代码   背景。通知后台处理已经过   完成后我们只需要使用return语句

 @Override
    protected String doInBackground(String... params) {
        ToWebservice toWebservice = new ToWebservice(ScanPage.this);
        toWebservice.postDataHdr(Branch, DocNo, Status, Date);
        toWebservice.postDataDtl(DocNo);
        return Status; // response
    }

答案 1 :(得分:1)

返回任何这样的字符串,

 @Override
protected String doInBackground(String... params) {
    ToWebservice toWebservice = new ToWebservice(ScanPage.this);
    toWebservice.postDataHdr(Branch, DocNo, Status, Date);
    toWebservice.postDataDtl(DocNo);
    return Status;
}

答案 2 :(得分:1)

你在doinBackground中返回Null 并在onPostExecute你有条件 if(结果!= null) 所以它永远不会被称为 ... 只需删除onPostExecute中的条件

答案 3 :(得分:1)

从[{1}}返回的任何内容都是doInbackground()的输入内容。  在您的情况下,您将从postExecute()doInBackground()返回null 当结果不为空时关闭对话框。

从postExecute中删除if条件。因为Dialog在任何情况下都必须关闭。

postExecute()