RxJava轮询简示 How To Use 创建 private var _connectJob: Disposable? = null private fun startConnectJob() { if (_connectJob != null _connectJob?.isDisposed == false) return _connectJob = Observable.interval(0, 5, TimeUnit.S
RxJava轮询简示
- How To Use
创建
private var _connectJob: Disposable? = nullprivate fun startConnectJob() {
if (_connectJob != null && _connectJob?.isDisposed == false) return
_connectJob = Observable.interval(0, 5, TimeUnit.SECONDS)
.subscribeOn(Schedulers.newThread())
.subscribe {
//your job
}
}
private fun stopConnectJob() {
if (_connectJob != null) {
if (!_connectJob!!.isDisposed) {
_connectJob!!.dispose()
_connectJob = null
}
}
}
销毁
override fun onDestroy() {stopConnectJob()
super.onDestroy()
}