为什么重要的是使用服务后台任务? [英] Why is it important to use Services for background tasks?
问题描述
我知道我应该用服务在Android中做的东西,从一个非UI线程的背景。
I know I should use Services in Android to do stuff in the background from a non-UI thread.
不过,我想知道什么是错的只是产卵一个后台线程做从Activity类的工作(onClick事件为例内)。
However, I would like to know what is wrong with just spawning a background thread to do the work from an Activity class (within an onClick event for example).
先谢谢了。
推荐答案
其实,服务
用于长时间运行的任务,尤其是那些,即运行在你的活动不运行。 主题
可用于使您的活动里面的一些任务。这个规定,一个发
,您活动中创建
,不能生活所创建它的活动之外,当一个服务
即可。希望这有助于。
Actually, Services
are used for long running tasks, especially those, that run when your activity is not running. Threads
can be used for making some tasks inside your activity. This states, that a Thread
, created inside your Activity
, can not live outside of the activity that's created it, when a Service
can. Hope this helps.
这篇关于为什么重要的是使用服务后台任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!