Why is it important to use Services for background tasks?

我们两清 提交于 2019-12-13 20:29:27

问题


I know I should use Services in Android to do stuff in the background from a non-UI thread.

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).

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/7737067/why-is-it-important-to-use-services-for-background-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!