Android中AsyncTask和Thread的使用场景

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 所谓的独立,不是针对在爱情里;在整个社会群体,都需要独立,有一个可以自我独立的能力很重要。 突然恋爱了,突然朋友来...
    孙大敏的癫狂阅读 270评论 0 0
  • BottomNavigationView、下拉刷新、滑动菜单一、BottomNavigationView在 bui...
    为梦想战斗阅读 310评论 0 0
  • 冷得有点不知所措,于是加了件外套。还是行骑自行车上班。 来了位新同事,老大说,教下他。 嗯。怎么教?我最怕教人了,...
    流浪痴人阅读 202评论 0 0
  • 还记得那一天 我轻轻地看了你一眼 还记得那一天 我爱上了你的笑脸 如果时间亘古不变 也许就不会忘了昨天 如果明天一...
    爱哭的流氓阅读 276评论 0 0
  • 我的心底藏着一个秘密 尤其不能告诉的 是你 你说我们的友谊会天长地久 我想我对你的爱将矢志不渝 你并不知道这个秘密...
    冰点晚安阅读 305评论 4 6

友情链接更多精彩内容