728x90
원인
서비스에서 startForeground 호출 시점이 꼬이면 발생하는 예외

해결
onStartCommand() 에서 호출하던 startFroeground를 onCreate() 로 변경
private fun createNotificationChannel() {
...
startForeground(NOTIFICATION_ID, notification)
}
broadcastUpdate(BleObject.START_FOREGROUND_SERVICE, "startForegroundService")
}
override fun onCreate() {
super.onCreate()
createNotificationChannel()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
when (intent?.action) {
BleObject.START_FOREGROUND_SERVICE -> {
//createNotificationChannel() 여기에서 onCreate() 로 변경
bleRepository.initBeaconManager(this)
bleRepository.initBeaconListener(this)
bleRepository.startBeaconScan()
}
BleObject.STOP_FOREGROUND_SERVICE -> {
bleRepository.stopBeaconScan()
stopForegroundService()
}
BleObject.READ_SENSOR -> {
getSensorDataRoutin()
}
}
// 작업 수행 코드
return START_REDELIVER_INTENT
}
참고
Android 8.0 동작 변경 사항 | Android 개발자 | Android Developers
System and API behavior changes that can affect apps running on Android 8.0.
developer.android.com
728x90