gpt4 book ai didi

android - 异步任务 : Is onPostExecute guaranteed to run after all calls to onProgressUpdate?

转载 作者:行者123 更新时间:2023-11-29 00:50:27 24 4
gpt4 key购买 nike

我想知道在调用 AsyncTask#onPostExecute 之后是否有可能对 AsyncTask#onProgressUpdate 进行“剩余”调用?我正在使用它们在同一个 TextView 上设置文本,我不想设置诸如“Done!”之类的文本。然后在稍后用诸如“差不多 - 90%”之类的文本覆盖它

此外,我假设 onProgressUpdate 方法的工作方式类似于 SwingWorker 方法,因为对 publishProgress 的多次调用可能会在调用 onProgressUpdate 发生。我真的很想知道“较新”和“较旧”进度更新在参数上的位置 - 即参数中位置 0 或位置 progress.length 的最新更新?

最佳答案

publishProgress 的代码是:

protected final void publishProgress(Progress... values) {
sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
new AsyncTaskResult<Progress>(this, values)).sendToTarget();
}

sendToTarget 调用使用 Handler#sendMessage,文档称其“将消息推送到消息队列的末尾”。我理解这意味着您不会得到任何无序的更新,并且它们会堆积起来。此外,对于每个 publishProgress 调用,都会有一个相应的 onProgressUpdate 调用。

关于android - 异步任务 : Is onPostExecute guaranteed to run after all calls to onProgressUpdate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3137696/

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