From 24f7361805ddcd270e64ace60d7cfbaaed56f944 Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Mon, 16 Nov 2026 14:25:50 +0900 Subject: [PATCH] =?UTF-8?q?=EC=83=9D=EB=AA=85=EC=A3=BC=EA=B8=B0=EC=99=80?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC=EB=90=9C=20CoroutineScope=EB=A5=BC=20life?= =?UTF-8?q?cycleScope=EB=A1=9C=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SystemStatusFragment: 플래시/거울 타이머, 상태 모니터링, 월간 사용량 조회 코루틴을 viewLifecycleOwner.lifecycleScope로 전환해 뷰 종료 시 자동 취소되도록 개선 - LauncherActivity: saveToPrivateVault() 백그라운드 복사 작업을 lifecycleScope.launch(Dispatchers.IO)로 전환 --- .../kotlin/bums/lunatic/launcher/LauncherActivity.kt | 2 +- .../bums/lunatic/launcher/home/SystemStatusFragment.kt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt index 5b6cc2c3..0a9c62f8 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt @@ -243,7 +243,7 @@ open class LauncherActivity : CommonActivity() { // 💡 URI로부터 파일을 읽어서 프라이빗 폴더로 복사하는 함수 private fun saveToPrivateVault(uri: Uri) { var fileName = "shared_${System.currentTimeMillis()}" - CoroutineScope(Dispatchers.IO).launch { + lifecycleScope.launch(Dispatchers.IO) { try { // 1. 원본 파일명 및 총 파일 크기(용량) 알아내기 var totalFileSize = 0L // 💡 파일 크기를 담을 변수 추가 diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/SystemStatusFragment.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/SystemStatusFragment.kt index 067af0ba..e00b8b51 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/SystemStatusFragment.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/SystemStatusFragment.kt @@ -28,6 +28,7 @@ import android.provider.Settings import android.util.TypedValue import android.view.LayoutInflater import android.view.View +import androidx.lifecycle.lifecycleScope import android.view.ViewGroup import android.widget.LinearLayout import android.widget.SeekBar @@ -230,7 +231,7 @@ class SystemStatusFragment : Fragment() { binding.btnQuickFlash.setTextColor(Color.YELLOW) // 30초 카운트다운 시작 - flashTimerJob = CoroutineScope(Dispatchers.Main).launch { + flashTimerJob = viewLifecycleOwner.lifecycleScope.launch { for (i in time downTo 1) { binding.btnQuickFlash.text = "flashlight_off" delay(1000L) @@ -307,7 +308,7 @@ class SystemStatusFragment : Fragment() { Blog.LOGE("거울 실행 실패: ${e.message}") } }, androidx.core.content.ContextCompat.getMainExecutor(requireContext())) - CoroutineScope(Dispatchers.Main).launch { + viewLifecycleOwner.lifecycleScope.launch { for (i in 30 downTo 1) { if (!mirrorDialog.isShowing) break timerText.text = "거울 모드 종료까지 $i" + "초" @@ -392,7 +393,7 @@ class SystemStatusFragment : Fragment() { private fun startMonitoring() { if (monitorJob?.isActive == true) return - monitorJob = CoroutineScope(Dispatchers.Main).launch { + monitorJob = viewLifecycleOwner.lifecycleScope.launch { while (isActive) { updateSystemInfo() updateNetworkSpeed() @@ -580,7 +581,7 @@ class SystemStatusFragment : Fragment() { return } - CoroutineScope(Dispatchers.IO).launch { + viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { try { val networkStatsManager = requireContext().getSystemService(Context.NETWORK_STATS_SERVICE) as NetworkStatsManager val calendar = Calendar.getInstance()