i want download files @ same time(simultaneously) asynctask.
i figure out how download multiple files simultaneously. tried search on internet found nothing, found in lot of applications can done.
i want improve stability of app (android) every time perform or refresh ui not slow down process ---> "lag".
excuse english not speak well.thank much.
create download task this:
public class newspaperdownloader extends asynctask<void, void, file> { url urltodownload; public downloadertask(url urltodownload) { this.urltodownload = urltodownload; } protected void onpreexecute() { // prepare download here } protected string doinbackground(void... params) { // download here [...] } protected void onpostexecute(file downloadedfile) { // download } } if don't know how download files in asynctask on android, have @ examples provided here.
and call downloads this:
// task 1 downloadtask task1 = new downloadtask(urltodownload); task1.executeonexecutor(asynctask.thread_pool_executor); // task 2 downloadtask task2 = new downloadtask(urltodownload); task2.executeonexecutor(asynctask.thread_pool_executor); // task 3 downloadtask task3 = new downloadtask(urltodownload); task3.executeonexecutor(asynctask.thread_pool_executor); update
download url list:
list<url> urls = new arraylist<url>(); urls.add(...); [...] for(url url : urls) { downloadtask task = new downloadtask(url); task.executeonexecutor(asynctask.thread_pool_executor); }
Comments
Post a Comment