I'm trying to download multiple files from my server to my device.
Here is what i've done:
On Activities
...
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra(DownloadService.URL, url);
startService(intent);
DownloadService class
public class DownloadService extends IntentService {
...
@Override
protected void onHandleIntent(final Intent intent) {
new Thread(new Runnable() {
@Override
public void run() {
// Download code...
}
}).start();
}
My IntentService can be launched multiple times from any Activity (for example i want to download file0, file1, ..., fileN): that's why i use a Thread inside onHandleIntent, in order to download them separately.
And here is my problem: how can i cancel / interrupt the download of a specific Thread, launched from IntentService? There is no UI update during the download, but only a Notification with a progress bar, of course updated from Thread.
A file's size can be of 1GB and i'm trying to undo this download.
EDIT 1 :
DownloadManager is very useful, i know, but my file is composed by multiple sub-files, which are created one by one by server at runtime. I've already tried this way, but this is not what i'm looking for.