Search code examples
javaandroidmultithreadingkotlinthread-sleep

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?


Solution

  • 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.