测试手机Xiaomi note3 with Anroid8.0.1
代码:
Handler(Looper.getMainLooper()).post(object : Runnable {
override fun run() {
Utils.appendLog("Handler 10s interval")
Handler(Looper.getMainLooper()).postDelayed(this, 10000)
}
})
日志:
代码:
private val SENDING_RETRY_DELAY_MS = 10000L
private var mTimeoutDisposable: Disposable? = null
private fun periodicTimeoutObservable(): Observable<Long> {
return Observable.interval(SENDING_RETRY_DELAY_MS,
SENDING_RETRY_DELAY_MS,
TimeUnit.MILLISECONDS)
}
private fun startPrintLog() {
if (mTimeoutDisposable == null) {
mTimeoutDisposable = periodicTimeoutObservable().subscribe {
Utils.appendLog("Observable 10s interval")
}
}
}
private fun stopPrintLog() {
if (mTimeoutDisposable != null) {
mTimeoutDisposable!!.dispose()
mTimeoutDisposable = null
}
}
关于Obaserval的依赖,在之前的项目中使用如下(不确定是一代还是二代的旧版本):
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.1.6'
implementation 'io.reactivex:rxjava-math:1.0.0'
Kotlin使用上面的会提示异常,故改成如下依赖(RxJava 3.x 三代版本):
implementation 'io.reactivex.rxjava3:rxjava:3.1.3'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
日志:
|