AsyncTask的onPostExecute不会被调用 [英] AsyncTask onPostExecute not being called

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

问题描述

我工作的这个项目是稍微复杂一些,但我做了这个简单的测试,试图追查什么是错我的code。进度对话框永不解散。我有它在一个点上,他们并没有返回null。

 公共类SyncTestActivity延伸活动{
    / **当第一次创建活动调用。 * /
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        新mTask(本).execute();
    }    公共类mTask扩展的AsyncTask<太虚,太虚,太虚> {        上下文mContext;        ProgressDialog progressDialog;        公共mTask(上下文aContext){
            mContext = aContext;
        }        @覆盖
        在preExecute公共无效(){            progressDialog =新ProgressDialog(mContext);
            progressDialog.setMessage(新建...);
            progressDialog.show();
        }        @覆盖
        公共无效doInBackground(虚空...... PARAMS){
            返回null;
        }        公共无效onPostExecute(虚空...... PARAMS){
            progressDialog.dismiss();
            返回null;
        }
    }}


解决方案

参数是错误的,这样做:

  @覆盖
    保护无效onPostExecute(虚空结果){
        progressDialog.dismiss();
        返回;    }

The project I'm working on is slightly more complicated but I made this simple test to try to track down what was wrong with my code. The progress dialog never dismisses. I had it at one point where they weren't returning null. '

public class SyncTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new mTask(this).execute();
    }

    public class mTask extends AsyncTask<Void, Void, Void> {

        Context mContext;

        ProgressDialog progressDialog;

        public mTask(Context aContext) {
            mContext = aContext;
        }

        @Override
        public void onPreExecute() {

            progressDialog = new ProgressDialog(mContext);
            progressDialog.setMessage("New...");
            progressDialog.show();
        }

        @Override
        public Void doInBackground(Void... params) {
            return null;
        }  

        public Void onPostExecute(Void... params) {
            progressDialog.dismiss();
            return null;


        }
    }

}

解决方案

The parameters are wrong, use this:

    @Override
    protected void onPostExecute(Void result) {
        progressDialog.dismiss();
        return;

    }

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

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