생명주기와 분리된 CoroutineScope를 lifecycleScope로 전환
- SystemStatusFragment: 플래시/거울 타이머, 상태 모니터링, 월간 사용량 조회 코루틴을 viewLifecycleOwner.lifecycleScope로 전환해 뷰 종료 시 자동 취소되도록 개선 - LauncherActivity: saveToPrivateVault() 백그라운드 복사 작업을 lifecycleScope.launch(Dispatchers.IO)로 전환
This commit is contained in:
@@ -243,7 +243,7 @@ open class LauncherActivity : CommonActivity() {
|
|||||||
// 💡 URI로부터 파일을 읽어서 프라이빗 폴더로 복사하는 함수
|
// 💡 URI로부터 파일을 읽어서 프라이빗 폴더로 복사하는 함수
|
||||||
private fun saveToPrivateVault(uri: Uri) {
|
private fun saveToPrivateVault(uri: Uri) {
|
||||||
var fileName = "shared_${System.currentTimeMillis()}"
|
var fileName = "shared_${System.currentTimeMillis()}"
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
// 1. 원본 파일명 및 총 파일 크기(용량) 알아내기
|
// 1. 원본 파일명 및 총 파일 크기(용량) 알아내기
|
||||||
var totalFileSize = 0L // 💡 파일 크기를 담을 변수 추가
|
var totalFileSize = 0L // 💡 파일 크기를 담을 변수 추가
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.provider.Settings
|
|||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
@@ -230,7 +231,7 @@ class SystemStatusFragment : Fragment() {
|
|||||||
binding.btnQuickFlash.setTextColor(Color.YELLOW)
|
binding.btnQuickFlash.setTextColor(Color.YELLOW)
|
||||||
|
|
||||||
// 30초 카운트다운 시작
|
// 30초 카운트다운 시작
|
||||||
flashTimerJob = CoroutineScope(Dispatchers.Main).launch {
|
flashTimerJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||||
for (i in time downTo 1) {
|
for (i in time downTo 1) {
|
||||||
binding.btnQuickFlash.text = "flashlight_off"
|
binding.btnQuickFlash.text = "flashlight_off"
|
||||||
delay(1000L)
|
delay(1000L)
|
||||||
@@ -307,7 +308,7 @@ class SystemStatusFragment : Fragment() {
|
|||||||
Blog.LOGE("거울 실행 실패: ${e.message}")
|
Blog.LOGE("거울 실행 실패: ${e.message}")
|
||||||
}
|
}
|
||||||
}, androidx.core.content.ContextCompat.getMainExecutor(requireContext()))
|
}, androidx.core.content.ContextCompat.getMainExecutor(requireContext()))
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
for (i in 30 downTo 1) {
|
for (i in 30 downTo 1) {
|
||||||
if (!mirrorDialog.isShowing) break
|
if (!mirrorDialog.isShowing) break
|
||||||
timerText.text = "거울 모드 종료까지 $i" + "초"
|
timerText.text = "거울 모드 종료까지 $i" + "초"
|
||||||
@@ -392,7 +393,7 @@ class SystemStatusFragment : Fragment() {
|
|||||||
private fun startMonitoring() {
|
private fun startMonitoring() {
|
||||||
if (monitorJob?.isActive == true) return
|
if (monitorJob?.isActive == true) return
|
||||||
|
|
||||||
monitorJob = CoroutineScope(Dispatchers.Main).launch {
|
monitorJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
updateSystemInfo()
|
updateSystemInfo()
|
||||||
updateNetworkSpeed()
|
updateNetworkSpeed()
|
||||||
@@ -580,7 +581,7 @@ class SystemStatusFragment : Fragment() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val networkStatsManager = requireContext().getSystemService(Context.NETWORK_STATS_SERVICE) as NetworkStatsManager
|
val networkStatsManager = requireContext().getSystemService(Context.NETWORK_STATS_SERVICE) as NetworkStatsManager
|
||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
|
|||||||
Reference in New Issue
Block a user