I have many tasks,and I should use Multi-thread to process them ,what’s the best solution,?the mean is I can use The least number of threads but process the most task With the fastest time.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think
AsyncTaskis useful for you. You can find more about it Android – AsyncTask in this nice explanation and example given.And if you want to use
Threadthen you have to manage all the threads, and also be sure aboutnot to blocking the UI Thread.Difference between Handler and AsyncTask…
1.The Handler is associated with the application’s main thread. it handles and schedules
messages and runnables sent from background threads to the app main thread.
2.AsyncTask provides a simple method to handle background threads in order to update the UI without blocking it by time consuming operations.
The answer is that both can be used to update the UI from background threads, the difference would be in your execution scenario. You may consider using handler it you want to post delayed messages or send messages to the MessageQueue in a specific order.
You may consider using AsyncTask if you want to exchange parameters (thus updating UI) between the app main thread and background thread in an easy convinient way.
Example for Threads, Handlers and AsyncTask in Android.
Thanks.