美文网首页
Android中AsyncTask和Thread的使用场景

Android中AsyncTask和Thread的使用场景

作者: Koudle | 来源:发表于2015-05-20 14:24 被阅读605次

For long-running or CPU-intensive tasks, there are basically two ways to do this: Java threads, and Android's native AsyncTask.
Neither one is necessarily better than the other, but knowing when to use each call is essential to leveraging the system's performance to your benefit.
Use AsyncTask for:
<li>Simple network operations which do not require downloading a lot of data
<li>Disk-bound tasks that might take more than a few milliseconds

Use Java threads for:
<li>Network operations which involve moderate to large amounts of data (either uploading or downloading)
<li>High-CPU tasks which need to be run in the background
Any task where you want to control the CPU usage relative to the GUI thread

And there are lot of good resources over internet which may help you:
http://www.vogella.com/articles/AndroidBackgroundProcessing/article.htmlhttp://www.mergeconflict.net/2012/05/java-threads-vs-android-asynctask-which.html

相关文章

网友评论

      本文标题:Android中AsyncTask和Thread的使用场景

      本文链接:https://www.haomeiwen.com/subject/obmlqttx.html