简体   繁体   中英

how can replace Thread.sleep() with RXJava

when I use Thread.sleep() for the delay in my app I get crash InterruptedException .

I have to use Thread.sleep() because I send Command to hardware and need to get data after 1 second.

can I use RX java for this problem? or other ways?

Yes you can replace Thread.sleep() in RX java using delay in Observable. Here how to do it:

Observable.delay(5000, TimeUnit.MILLISECONDS)

using interval will do thing infinite time at the interval of provided time.

Use interval in RxJava

Observable.interval(1, TimeUnit.SECONDS)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM