Where it is better to start a new thread for time consuming operations?
I'm wondering what is the best practice about initiation of new threads
in Android or that is just a matter of taste. Shall I start threads
for time consuming operations directly from the Activity
or I need to开发者_高级运维 delegate this to a separate class?
AndroidNoob,
Here is a good article on this from the Android Developers Blog: http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html
It looks like they create a new class for the AsyncTask
and launch it from their UI Activity.
Hope this helps, good luck!
I think it's mainly a question of reusability.
If your time consuming operation is only used by one class it's ok (in my opinion) to use a Thread.
If your operation will be used by more classes you should think about an AsyncTask.
Regards, Tim
精彩评论