Lifecycle 에 맞춰 RxJava Stream 재실행하기

SeongUg Steve Jung
Aug 6 · 4 min read

RxJava Stream 실행 관리가 필요한가?

1. Lifecycle 관리하는 코드 만들기

2. RxLifecycleObserver 만들기

3. Activity 에 Controller 를 정의하고 ViewModel 과 공유하기

4. RxLifecycle 생성 코드 가독성 높이기

5. LifecycleObserver 코드 가독성 높이기

// 기존
class MainViewModel(delegate: LifecycleDelegate) {
fun onResume() { Observable.compose(delegate).subscribe() }
// 변경
class MainViewModel(delegate: LifecycleDelegate): LifecycleDelegate by delegate {
init {
+onVisible { Observable.subscribe() }


SeongUg Steve Jung

Written by

Android Developer, Google Developers Experts

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade