Last active
August 5, 2017 17:21
-
-
Save sakiwei/f0200f84c8fa1a2c87a0db3725d0cf67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : LifecycleActivity() { | |
// create a LifecycleCompositeDisposable which will be disposed at onPause() | |
val disposableBag by lazy { createOnPauseCompositeDisposable() } | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// keep firing a number on each second, | |
// until LifecycleActivity.onPause() is triggered | |
Observable.interval(1000, TimeUnit.MILLISECONDS) | |
.doOnDispose { | |
Log.d(TAG, "Disposed!") | |
} | |
.subscribe { | |
Log.d(TAG, it.toString()) | |
} | |
// remember to add the disposable to the CompositeDisposable | |
.addTo(disposableBag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment