Android : Using parallel Threads for different network operations

on Friday, July 25, 2014


I'm writing an app that should first run 2 methods one by one that each takes 2 second to get first tokenId and after that run 3-5 calls to different web services to get data. each call to web service takes 5 seconds, so I don't want to wait 20 sec while running them one by one.


To get connect and then get token :


connect() after I getting result, run getToken ().


After that I need to display data that I getting from 3-5 web services,so I thought doing it in parallel to save some time. I don't want to wait to each be finished and then run the next, so I probably I need to do it with 3-5 parallel Threads and then each Thread will save the data to sharable place, after all done display data on UI.


Some questions:


1- To implement connect() and AFTER that getToken() I should run AsyncTask for connect() and then in onPostExecute() start a new AsyncTask for getToken() with the result from connect()?


2- Because all my work in each web servive is sending data and waiting for it to come - is it the right thing to create 3-4 Theards when each innitilezed to call different web service and get the result - after that save it to global place and only after all done to display it ? how to implement thing like that?


0 comments:

Post a Comment