简体   繁体   中英

Check when a file has finished downloading in Eclipse

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM