onProgressUpdate错过一些出版

编程入门 行业动态 更新时间:2024-10-15 18:23:02
本文介绍了onProgressUpdate错过一些出版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有可能是某些电话publishProgress由on​​ProgressUpdate错过了什么?我的意思是有可能有可能是doInBackground和onProgressUpdate回调之间的一个传递思念使用publishProgress通话。因为我看到了。

Is it possible that some calls publishProgress missed by onProgressUpdate? I mean is it possible there may be one transfer miss between doInBackground and onProgressUpdate callbacks with using publishProgress call. Because I see that.

class DoSomething extends AsyncTask Void, String, Void { String[] S = new String[] {"a", "b", "c", "d"}; void doInBackground(Void... ps) { for(String s : S) { publishProgress(s); } } void onProgressUpdate(String... vs) { Log.d("", vs[0]); }

我所遇到的导致结果

A B B D

What i am encountering that resulting

a b b d

推荐答案

确定。我深掘,发现答案是:之间的消息传递 doInBackground 和 onProgressUpdate 不是序列是异步的(从基类名称)。在 doInBackground 的任何调用与 publishProgress(XX)将最终达到 onProgressUpdate 但不是一对之一。结果例如,很假演示:

Ok. I dug deep and found the answer that: message transmission between doInBackground and onProgressUpdate is not serial that is asynchronous (from the base class name). Any call in doInBackground with publishProgress(xx) will eventually reach to onProgressUpdate but not one-to-one. For example, very dummy demonstration:

doInBackgroud() { String s; for(i=1 to 10) { s = i.toString(); publishProgress(s); } } onProgressUpdate(String par) { Log.d(par); }

可以是结果为:1 2 2 3 4 5 5 5 6 7结果塔是什么?通过参考和 onProgressUpdate 调用,它是记录其价值的时候不要担心,我们发送局部变量s(在doinback),有概率 doInBackground 正在改变s的值。这在 onProgressUpdate 产生意想不到的价值。但是,所有publishProgress调用调用 onProgressUpdate 方法。结果如果我们写道:

can be result as: 1 2 2 3 4 5 5 5 6 7 What tha ? Dont worry, we sending the local variable s (in doinback.) by reference and by the time onProgressUpdate invoked and it is logging its value, there is probability that doInBackground is changing the value of s. That results unexpected value in the onProgressUpdate. But all publishProgress calls invoke the onProgressUpdate method. If we wrote:

doInBackgroud() { for(i=1 to 10) { String s = i.toString(); publishProgress(s); } } onProgressUpdate(String par) { Log.d(par); }

这个时候正常情况下,结果必然是:1 2 3 4 5 6 7 8 9 10结果而这正是我们所期望的,不是吗?结果如果有更好的主意,我想听到结果和任何评论将被精心欢迎。结果注意:也许过于简单的例子,但我保存一周

this time under normal conditions, result must be : 1 2 3 4 5 6 7 8 9 10 and this is what we expect, isn't it? if there is better idea, i would like to hear that And any comments will be well-welcomed. Note: Maybe too simple case, but saved my week.

更多推荐

onProgressUpdate错过一些出版

本文发布于:2023-10-08 15:14:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1473002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:onProgressUpdate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!