AsyncTask的和线程之间真正的区别 [英] Real difference between AsyncTask and Thread

查看:157
本文介绍了AsyncTask的和线程之间真正的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读Android文档( AsyncTask的,的)和的 vogella教程这件事情,但我怀疑呢。

I have been reading Android documentation (AsyncTask, Thread) and vogella tutorial about this matter, but I have doubts yet.

例如,我想发送一条消息,因为Android应用到服务器。我想处理它的响应。我应该怎么使用?

For example, I wish send a message since an Android app to a server. And I would like process its response. What should I use?

我看到他们创建新线程为不会阻止用户界面的例子,但这样一来,我们没有过程的进展,还必须处理线程内的响应,因为run()方法不返回任何

I have seen examples where they create a new Thread for not block UI, but this way we have not the progress of process, also you have to process the response within the thread because the run() method don't returning anything.

AsyncTask的似乎比线程更好的选择,但我不知道是否有关于Android如何运行的AsyncTask或线程一些consecuences。

AsyncTask seems better option than Thread, but I don't know if there are some consecuences about how Android run an AsyncTask or a Thread.

推荐答案

请阅读此博客

<一个href=\"http://crazyaboutandroid.blogspot.in/2011/12/difference-between-android.html\">http://crazyaboutandroid.blogspot.in/2011/12/difference-between-android.html

和具体内容是:

Android的服务,螺纹,IntentService和AsyncTask的区别

何时使用?

When to use ?

服务

   Task with no UI, but shouldn't be too long. Use threads within service for long tasks.

主题

- Long task in general.

- For tasks in parallel use Multiple threads (traditional mechanisms)

的AsyncTask

- Small task having to communicate with main thread.

- For tasks in parallel use multiple instances OR Executor 

这篇关于AsyncTask的和线程之间真正的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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