fix: Task 7 완료 - ForeGroundService onDestroy 구현으로 리시버/스코프 누수 제거

- ForeGroundService.kt:
  * serviceScope에 SupervisorJob() 추가해 개별 코루틴 실패가 서비스 전체 스코프를 취소하지 않도록 개선
  * onDestroy() 신규 구현: bluetoothreceiver unregisterReceiver 호출(예외 방어 포함) 및 serviceScope Job 취소
- TODO.md: 1-3 항목 완료 처리
- 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (3s)
This commit is contained in:
2026-11-16 11:15:53 +09:00
parent e814996286
commit f31b967ef2
2 changed files with 9 additions and 2 deletions
@@ -434,7 +434,7 @@ class ForeGroundService : Service() {
var blueToothAdapter:BluetoothAdapter? = null
private var mWorkManager: WorkManager? = null
private val serviceScope = CoroutineScope(Dispatchers.Default)
private val serviceScope = CoroutineScope(Dispatchers.Default + kotlinx.coroutines.SupervisorJob())
val NOTIF_ID = 830721
override fun onCreate() {
super.onCreate()
@@ -925,6 +925,13 @@ class ForeGroundService : Service() {
}
}
override fun onDestroy() {
try {
unregisterReceiver(bluetoothreceiver)
} catch (_: Exception) { }
serviceScope.coroutineContext[kotlinx.coroutines.Job]?.cancel()
super.onDestroy()
}
}