I'm trying to download multiple files one by one (file is downloaded, we start downloading the next file). Using this method I can keep track of the files being downloaded. The problem is that I'm using the following code for executing a Task:
File file = null;
for(int i=0; i< videos.length; i++) {
file = new File(root.getPath() + videos[i]);
boolean exists = file.exists();
if(exists){
//tv.append("
"+fileNames[i]+" already exists");
continue;
}
else {
currentFile = videos[i];
new DownloadFileAsync().execute(videoURL+videos[i],videos[i]);
}
file = null;
}
As you can see, I call new DownloadFileAsync().execute(videoURL+videos[i],videos[i]); in a loop which obviously start a task for each of the files and downloads them simultaneously.
My question is: How can I run execute the task for a specific file, check if it has been downloaded- if yes, proceed with next file by executing a task for it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…