为什么重要的是使用服务后台任务? [英] Why is it important to use Services for background tasks?

查看:148
本文介绍了为什么重要的是使用服务后台任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我应该用服务在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屋!

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