class MyService : Service(){
override fun onBind(p0: Intent?): IBinder? {
}
}
<service android:name=".MyService"
android:enabled="true"
android:exported="true">
</service>
val intent = Intent(this, MyService::class.java)
startService(intent)
val intent = Intent("ACTION_OUTER_SERVICE")
intent.setPackage("com.example.test_outter")
startService(intent)
stopService(intent)
val connection: ServiceConnection = object : ServiceConnection{
override fun onServiceConnected(p0: ComponentName?, p1: IBinder?) {
} // bindService() 시 자동 호출
override fun onServiceDisconnected(p0: ComponentName?) {
} // unbindService() 시 자동 호출
}
val intent = Intent(this, MyService::class.java)
bindService(intent, connection, Context.BIND_AUTO_CREATE)
unbindService(connection)
Unbounded 의 경우 startService()에서 객체가 생성되면 onCreate() -> onStartCommand() 를 통해 실행된다.
이후 startService()가 실행될 경우, onStartCommand() 만 다시 호출한다.
Bounded 의 경우 bindService()를 통해 객체를 생성하면 onCreate() -> onBind() 가 실행 된다.
이후 bindService() 를 실행할 경우 onBind() 만 다시 호출된다.