服务、异步任务和异步任务之间的区别线? [英] Difference between Service, Async Task & Thread?

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

问题描述

Service, Async Task & 有什么区别?线.如果我没有错的话,所有这些都用于在后台做一些事情.那么,如何决定使用哪个以及何时使用?

What is the difference between Service, Async Task & Thread. If i am not wrong all of them are used to do some stuff in background. So, how to decide which to use and when?

推荐答案

可能你已经看过关于它们的文档说明了,我就不重复了,我会尽量用自己的话来回答,希望它们能帮助到你你.

Probably you already read the documentation description about them, I won't repeat them, instead I will try to give answer with my own words, hope they will help you.

  • 服务就像一个活动,但没有用户界面.例如,如果您想获取天气,则可能不会为其创建空白活动,为此您将使用服务.

  • Service is like an Activity but has no user interface. Probably if you want to fetch the weather for example you won't create a blank activity for it, for this you will use a Service.

线程就是线程,可能你已经从其他部分知道了.您需要知道不能从线程更新 UI.您需要为此使用处理程序,但请进一步阅读.

A Thread is a Thread, probably you already know it from other part. You need to know that you cannot update UI from a Thread. You need to use a Handler for this, but read further.

AsyncTask 是建议使用的智能线程.智能,因为它可以帮助它的方法,并且在UI线程上运行三个方法,这很好更新UI​​组件.

An AsyncTask is an intelligent Thread that is advised to be used. Intelligent as it can help with it's methods, and there are three methods that run on UI thread, which is good to update UI components.

我经常使用服务,AsyncTasks.线程更少,或者根本不线程,因为我可以用 AsyncTask 做几乎所有事情.

I am using Services, AsyncTasks frequently. Thread less, or not at all, as I can do almost everything with AsyncTask.

这篇关于服务、异步任务和异步任务之间的区别线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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