gpt4 book ai didi

android - 为什么从不调用 AsyncTask<> 接口(interface)的 onProgressUpdate()?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:51 25 4
gpt4 key购买 nike

永远不会调用 onProgressUpdate(),您能告诉我为什么吗?

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();
}
}
}

最佳答案

您必须从 doInBackground 中手动调用 publishProgress

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

关于android - 为什么从不调用 AsyncTask<> 接口(interface)的 onProgressUpdate()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5224568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com