Rasoul Miri
Rasoul Miri

Reputation: 12222

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?

Upvotes: 1

Views: 876

Answers (2)

MD Ruhul Amin
MD Ruhul Amin

Reputation: 4502

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.

Upvotes: 2

Md. Asaduzzaman
Md. Asaduzzaman

Reputation: 15423

Use interval in RxJava

Observable.interval(1, TimeUnit.SECONDS)

Upvotes: 1

Related Questions