Reputation: 25
I am making an application where on clicking a button, the selected song list is to be downloaded and I need to begin downloading a file only when the file before it has completed downloading. Is there any way to confirm?
Upvotes: 1
Views: 202
Reputation: 124265
I am not Android or multi-threading expert so there may be better ways to do this, but from what I remember you could use Executors for this scenario, like
ExecutorService es = Executors.newFixedThreadPool(1);// allow only one task to run,
// place rest of task in queue
es.execute(new Runnable() {
@Override
public void run() {
//download file one
}
});
es.execute(new Runnable() {
@Override
public void run() {
//download file two
}
});
Downloading file in second task will be executed only if code in previous task will finish.
Upvotes: 1