Reputation: 503
I know AsyncTasks make things run on different threads. So after I log a user in should I grab their friends names, profile pic, etc. all using different asynctasks but simultaneously to minimize time?
Upvotes: 1
Views: 1041
Reputation: 1362
Yes you can if you want to store all your data in database and it is suppose to use on different actions.
But at a time max 5 to 6 asyncTask will run and if they are running and you want to execute some other asynctask on user action then that will be goes into queue and user might require more time to wiat in that case. for more details on multiple asynctask see this thread ..
I hope this all will clear your idea.
Upvotes: 0
Reputation: 3263
Yes and No
Using multiple threads doesn't necessarily mean that the job will be done faster.
The more threads you are running, the more context switching your gonna suffer.
If your gonna use normal thread i recommend you use a thread pool so things doesn't go out of hand.
Asynctasks use pools internally, and have 2 modes they can operate on, serial or parallel.
if you use execute() method it will run parallel on devices running API less than 13, and serially on ones running later APIs
To force parallel behavior after API 13 use executeOnExecutor()
For devices with multiple cores , go for the parallel behavior, ones with single core, many threads are bound to slow things down
Upvotes: 2
Reputation: 4338
You should typically use only a minimal subset of threads based on your needs. You should typically only use AsyncTasks for components that will operate for short periods of time and need to interact with the UI components separately from a different task.
By default, the ThreadPoolExecutor will decide how serialized multiple AsyncTasks would be if you called upon them. Try to do small tasks in a single AsyncTask, and if you need longer running threads, then consider doing a service that runs in the background.
Upvotes: 0