AsyncTask的VS主题的机器人 [英] Asynctask vs Thread in android

查看:73
本文介绍了AsyncTask的VS主题的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UI我想要做一些,我使用单独的thread.But我建议的其他背景工作。对于这样做的asynctask.What是AsyncTask的与主题之间的主要区别,在这种情况下,我使用的线程和AsyncTask的?

In UI I want to do some background work.For that i use separate thread.But i suggested by other do it in asynctask.What is the main difference between Asynctask and Thread,in which scenario i've to use Thread and Asynctask?.

推荐答案

对于长时间运行或CPU密集型任务,基本上有两种方法可以做到这一点:Java线程,和Android的原生的AsyncTask

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.

使用的AsyncTask为:

  1. 在简单的网络操作不要求下载大量数据的
  2. 磁盘密集型任务,可能超过几毫秒采取更多

使用Java线程的:

    涉及中度到大量数据(无论是上载或下载)
  1. 网络操作
  2. 这需要在后台运行
  3. 高CPU任务
  4. 要控制相对于GUI线程的CPU使用情况的任何任务
  1. Network operations which involve moderate to large amounts of data (either uploading or downloading)
  2. High-CPU tasks which need to be run in the background
  3. 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:

<一个href="http://www.vogella.com/articles/AndroidBackgroundProcessing/article.html">http://www.vogella.com/articles/AndroidBackgroundProcessing/article.html <一href="http://www.mergeconflict.net/2012/05/java-threads-vs-android-asynctask-which.html">http://www.mergeconflict.net/2012/05/java-threads-vs-android-asynctask-which.html

这篇关于AsyncTask的VS主题的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆