官方文档参考:https://www.android-doc.com/reference/android/app/Service.html
一,简介
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding [<service>](https://www.android-doc.com/reference/android/R.styleable.html#AndroidManifestService)
declaration in its package's AndroidManifest.xml
. Services can be started with [Context.startService()](https://www.android-doc.com/reference/android/content/Context.html#startService(android.content.Intent))
and [Context.bindService()](https://www.android-doc.com/reference/android/content/Context.html#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int))
.
Note that services, like other application objects, run in the main thread of their hosting process. This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to do that work. More information on this can be found in Processes and Threads. The [IntentService](https://www.android-doc.com/reference/android/app/IntentService.html)
class is available as a standard implementation of Service that has its own thread where it schedules its work to be done.
二,总结
1)service是一个应用组件,长时间运行在后台,不需要直接跟用户交互。
2)service运行在主线程,如果需要执行耗时的任务,得自己启动一个新的线程来执行。