Why is it important to use Services for background

2019-08-19 04:11发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-19 04:47

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.

查看更多
登录 后发表回答