I have three simultaneous instances of an AsyncTask for download three files. When two particular ones finish, at the end of onPostExecute() I check a flag set by each, and if both are true, I call startActivity() for the next Activity.
I am currently seeing the activity called twice, or something that resembles this type of behavior. Since the screen does that 'swipe left' kind of transition to the next activity, it sometimes does it twice (and when I hit back, it goes back to the same activity). It's obvious two versions of the activity that SHOULD only get called once are being put on the Activity stack.
The only way I can find that this is possible is if both AsyncTasks' onPostExecute() executed SO simultaneously that they were virtually running the same lines at the same time, since I set the 'itemXdownloaded' flag to true right before I check for both and call startActivity(). But this is happening enough that it's very hard for me to believe that both downloads are finishing precisely at the same time and having their onPostExecute()s so close together...
Any thoughts on what could be going on here?
General gist of code (details removed, ignore any syntactical errors I may have edited in):
// In onPostExecute()
switch (downloadID) {
case DL1:
dl1complete = true;
break;
case DL2:
dl2complete = true;
break;
case DL3:
dl3complete = true;
break;
}
// If 1 and 2 are done, move on (DL3 still going in background)
if ( downloadID != DL3 && dl1complete && dl2complete) {
ParentClass.this.startActivity(new Intent(ParentClass.this, NextActivity.class));
}