From 8c278c2fc4709346aaaae551c07732f8d12c837e Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Mon, 16 Nov 2026 11:12:16 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Task=204=20=EC=99=84=EB=A3=8C=20-=20Luna?= =?UTF-8?q?ticLauncher=20Toast=20=EB=B0=8F=20LauncherActivity=20onDestroy?= =?UTF-8?q?=20=EB=A9=94=EB=AA=A8=EB=A6=AC=20=EB=88=84=EC=88=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - LunaticLauncher.kt: companion object의 정적 Toast 강참조(var toast: Toast?)로 인한 Activity Context 누수 제거 -> applicationContext 기반 WeakReference로 전환 및 이전 Toast 취소 처리 유지 - LauncherActivity.kt onDestroy(): * sActivity === this 조건으로 정적 Activity 참조 null 해제 * hiddenLoader 내 모든 GeckoWeb 세션(session?.close(), releaseSession()) 종료 및 clear() 처리 * callBackHandler.removeCallbacksAndMessages(null) 호출로 대기 중인 콜백 제거 * connectivityManager.unregisterNetworkCallback 호출 시 ::connectivityManager.isInitialized 및 예외 방어 추가 - TODO.md: 1-2 항목 완료 처리 - 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (6s) --- TODO.md | 2 +- .../bums/lunatic/launcher/LauncherActivity.kt | 20 ++++++++++++++++++- .../bums/lunatic/launcher/LunaticLauncher.kt | 17 ++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 643cdbc3..afe8507e 100644 --- a/TODO.md +++ b/TODO.md @@ -43,7 +43,7 @@ - `app/src/main/kotlin/bums/lunatic/launcher/home/RssHome.kt:95` — `var home: RssHome? = null` 정적 참조로 Fragment 및 연결된 View/Binding 누수 위험. - **작업**: 정적 Activity/Fragment 참조를 `WeakReference` 또는 이벤트 버스(`SharedFlow`/`ViewModel`)로 대체하고, 최소한 `onDestroy()`/`onDestroyView()`에서 `null` 처리. -- [ ] **1-2. 전역 `Toast` 인스턴스의 `Context` 누수 해결** +- [x] **1-2. 전역 `Toast` 인스턴스의 `Context` 누수 해결** - `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()` 후 참조를 유지하지 않도록 변경. diff --git a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt index 3970f541..164d7eb0 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt @@ -976,7 +976,25 @@ open class LauncherActivity : CommonActivity() { // smsReceiver = null // } - networkCallback?.let { connectivityManager.unregisterNetworkCallback(it) } + if (::connectivityManager.isInitialized) { + networkCallback?.let { + try { + connectivityManager.unregisterNetworkCallback(it) + } catch (_: Exception) { } + } + } + networkCallback = null + hiddenLoader.values.forEach { gecko -> + try { + gecko.session?.close() + gecko.releaseSession() + } catch (_: Exception) { } + } + hiddenLoader.clear() + callBackHandler.removeCallbacksAndMessages(null) + if (sActivity === this) { + sActivity = null + } super.onDestroy() } diff --git a/app/src/main/kotlin/bums/lunatic/launcher/LunaticLauncher.kt b/app/src/main/kotlin/bums/lunatic/launcher/LunaticLauncher.kt index e5dd20e1..ebf155fe 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/LunaticLauncher.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/LunaticLauncher.kt @@ -59,19 +59,20 @@ internal class LunaticLauncher : Application() { } var privateCompletedDir : File? = null - var toast : Toast? = null + private var toastRef: java.lang.ref.WeakReference? = null fun Context.toast(msg: String) { val biggerText = SpannableStringBuilder(msg) biggerText.setSpan(RelativeSizeSpan(1.6f), 0, msg.length, 0) - val view: View = inflate(this, R.layout.simple_toast, null) + val appCtx = applicationContext ?: this + val view: View = inflate(appCtx, R.layout.simple_toast, null) view.findViewById(R.id.text).text = biggerText - if (toast==null) { - toast = Toast(this) - toast?.duration = Toast.LENGTH_SHORT - toast?.cancel() + toastRef?.get()?.cancel() + Toast(appCtx).apply { + duration = Toast.LENGTH_SHORT + this.view = view + toastRef = java.lang.ref.WeakReference(this) + show() } - toast?.view = view - toast?.show() } }