[android] 안전하게 flow 를 collect 하기! - android 에서는 보통 UI layer 에서 flow 가 collect 된다. LifecycleOwner.addRepeatingJob, Lifecycle.repeatOnLifecycle, Flow.flowWithLifecycle 등을 이용해서 쓸데없이 res 가 낭비되지 않도록 하는 방법에 대해 알아본다. 리소스 낭비 - CoroutineScope.launch, Flow.launchIn, LifecycleCoroutineScope.launchWhenX 를 사용하는 것은 Activity 가 bg 로 들어갈 때 Job 을 수동으로 취소해주지 않는 한 안전한 방법이 아니다. 위 API 들은 app 이 bg 상태에 있을 때도 flow producer 가 buffer 에 emit 을 하도록 하고, 따라서 .. 2021. 5. 11. 반응형 이전 1 다음