Service服务是Android四大组件之一,是Android提供的一种的 不需要和用户交互,且需要长期运行任务的解决方案。
Service是 Android中实现程序后台运行的解决方案,它非常适合执行那些不需要和用户交互 而且还要求长期运行的任务。 Service的运行不依赖于任何用户界面,即使程序被切换到后台, 或者用户打开了另外一个应用程序, Service仍然能够保持正常运行。
- 继承自Service类的。
- onBind()唯一抽象方法。 ```kotlin import android.app.Service import android.content.Intent import android.os.IBinder
class FloatLogo : Service() { override fun onBind(p0: Intent?): IBinder? { TODO(“Not yet implemented”) } }

```kotlin
class FloatLogo : Service() {
private val TAG = "FloatLogo"
override fun onCreate() {
Log.i(TAG, "onCreate: ")
super.onCreate()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.i(TAG, "onStartCommand: ")
return super.onStartCommand(intent, flags, startId)
}
override fun onBind(p0: Intent?): IBinder? {
Log.i(TAG, "onBind: ")
TODO("Not yet implemented")
}
}