Call more than 1 url simultaneously in Android through Asynctask?
I want to call more than one url and get the response from that with AsyncTask. Currently what happens is that I pass one url to AysncTask and then get the response of that and after that call another url. What I want to ha开发者_开发技巧ve is to pass all the urls at a time since doInBackground does take an array as argument. Once all the 3 urls are called get the response of each one of them.
You could create threads inside doInBackground
and then call the join
method on each one of them. You'd probably be better served by a thread pool though.
I was able to do that passing array of url in doInBackground and setting the return type for results as String[]. That gave me the response of each url called in string array in postExecute.
Anyways, Thanks for taking the time out and replying to the posts.
You can create multiple AsyncTask objects and execute them in parallel - assuming all URLs just have to fetch data.
精彩评论