From f31b967ef2e358ba1700881615502ea291bdb88d Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Mon, 16 Nov 2026 11:15:53 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Task=207=20=EC=99=84=EB=A3=8C=20-=20Fore?= =?UTF-8?q?GroundService=20onDestroy=20=EA=B5=AC=ED=98=84=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=A6=AC=EC=8B=9C=EB=B2=84/=EC=8A=A4=EC=BD=94?= =?UTF-8?q?=ED=94=84=20=EB=88=84=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ForeGroundService.kt: * serviceScope에 SupervisorJob() 추가해 개별 코루틴 실패가 서비스 전체 스코프를 취소하지 않도록 개선 * onDestroy() 신규 구현: bluetoothreceiver unregisterReceiver 호출(예외 방어 포함) 및 serviceScope Job 취소 - TODO.md: 1-3 항목 완료 처리 - 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (3s) --- TODO.md | 2 +- .../bums/lunatic/launcher/helpers/ForeGroundService.kt | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 1ec24337..e2d8c2c7 100644 --- a/TODO.md +++ b/TODO.md @@ -47,7 +47,7 @@ - `app/src/main/kotlin/bums/lunatic/launcher/LunaticLauncher.kt:62-75` — `companion object`의 `var toast: Toast? = null`에 `Context.toast()` 호출 시 전달된 `Context`(Activity일 수 있음)로 `Toast(this)`를 생성해 정적으로 유지함. - **작업**: `Toast(applicationContext)`를 사용하거나 매 호출 시 지역 `Toast`를 생성하고 기존 `toast?.cancel()` 후 참조를 유지하지 않도록 변경. -- [ ] **1-3. `BroadcastReceiver` 및 `Wearable.MessageClient` 리스너 미해제** +- [x] **1-3. `BroadcastReceiver` 및 `Wearable.MessageClient` 리스너 미해제** - `app/src/main/kotlin/bums/lunatic/launcher/helpers/ForeGroundService.kt:443` — `onCreate()`에서 `registerReceiver(bluetoothreceiver, filter)`를 호출하지만, `ForeGroundService` 클래스에 `onDestroy()`가 구현되어 있지 않아 리시버가 해제되지 않음. - `app/src/main/kotlin/bums/lunatic/launcher/home/NeoRssActivity.kt:715` — `onResume()`에서 `Wearable.getMessageClient(this).addListener(messageListener)`를 등록하나 대응하는 `onPause()`/`onDestroy()`의 `removeListener` 호출 여부 점검 및 해제 보장 필요. - **작업**: `ForeGroundService.onDestroy()`를 추가해 `unregisterReceiver(bluetoothreceiver)` 및 `serviceScope.cancel()` 수행, `NeoRssActivity.onPause()`에서 `removeListener(messageListener)` 호출 추가. diff --git a/app/src/main/kotlin/bums/lunatic/launcher/helpers/ForeGroundService.kt b/app/src/main/kotlin/bums/lunatic/launcher/helpers/ForeGroundService.kt index 9d033a17..2cf0f422 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/helpers/ForeGroundService.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/helpers/ForeGroundService.kt @@ -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() + } }