Why is it important to use Services for background

2019-08-19 04:09发布

问题:

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.