为什么的AsyncTask&所述的onProgressUpdate();>接口不会被调用? [英] Why the onProgressUpdate() of AsyncTask<> interface is never called?

查看:86
本文介绍了为什么的AsyncTask&所述的onProgressUpdate();>接口不会被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该onProgressUpdate()不会被调用,你能告诉我为什么吗?

 私有类LoginMe扩展的AsyncTask<上下文,太虚,布尔> {    @覆盖
    保护布尔doInBackground(上下文...为arg0){
        做一点事();
        返回true;
    }    @覆盖
    保护无效onProgressUpdate(无效... V){
        super.onProgressUpdate(五);
        Log.d(开发,林在onProgressUpdate());
    }    @覆盖
    保护无效onPostExecute(布尔结果){
        super.onPostExecute(结果);
        如果(结果){
            doOne();
        }其他{
            doTwo();
        }
    }
}


解决方案

您必须调用 publishProgress 从内部 doInBackground 手动


  

doInBackground(参数...),在调用
  后台线程立即
  在preExecute()之后完成
  执行。 ... 这一步也可以使用
  publishProgress(进展...)来
  公布进度的一个或多个单元。

  这些值公布在UI
  螺纹,在
  onProgressUpdate(进展...)的一步。


<一个href=\"http://developer.android.com/reference/android/os/AsyncTask.html\">http://developer.android.com/reference/android/os/AsyncTask.html

The onProgressUpdate() is never called, can you tell me why?

private class LoginMe extends AsyncTask<Context, Void, Boolean> {

    @Override
    protected Boolean doInBackground(Context... arg0) {
        doSomething();
        return true;
    }

    @Override
    protected void onProgressUpdate(Void... v) {
        super.onProgressUpdate(v);
        Log.d("Dev", "Im in onProgressUpdate()");
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        if (result) {
            doOne();
        } else {
            doTwo();
        }
    }
}

解决方案

You have to call publishProgress from within doInBackground manually.

doInBackground(Params...), invoked on the background thread immediately after onPreExecute() finishes executing. ... This step can also use publishProgress(Progress...) to publish one or more units of progress. These values are published on the UI thread, in the onProgressUpdate(Progress...) step.

http://developer.android.com/reference/android/os/AsyncTask.html

这篇关于为什么的AsyncTask&所述的onProgressUpdate();&GT;接口不会被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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