为什么的AsyncTask&所述的onProgressUpdate();&GT;接口不会被调用? [英] Why the onProgressUpdate() of AsyncTask<> interface is never called?
问题描述
该onProgressUpdate()不会被调用,你能告诉我为什么吗?
私有类LoginMe扩展的AsyncTask&LT;上下文,太虚,布尔&GT; { @覆盖
保护布尔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 withindoInBackground
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屋!