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]);
}
What i am encountering that resulting
a b b d
what happening to c?
Note: This is just illustration of my application, and this happens sometimes(not at all run), i could not write all the codes here because its too complicated. But in summary this is happening.
So any ideas?
Ok. I dug deep and found the answer that: message transmission between
doInBackgroundandonProgressUpdateis not serial that is asynchronous (from the base class name). Any call indoInBackgroundwithpublishProgress(xx)will eventually reach toonProgressUpdatebut not one-to-one.For example, very dummy demonstration:
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
onProgressUpdateinvoked and it is logging its value, there is probability thatdoInBackgroundis changing the value of s. That results unexpected value in theonProgressUpdate. But all publishProgress calls invoke theonProgressUpdatemethod.If we wrote:
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.