Skip to content

Instantly share code, notes, and snippets.

@sakiwei
Last active August 5, 2017 17:21
Show Gist options
  • Save sakiwei/f0200f84c8fa1a2c87a0db3725d0cf67 to your computer and use it in GitHub Desktop.
Save sakiwei/f0200f84c8fa1a2c87a0db3725d0cf67 to your computer and use it in GitHub Desktop.
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