I am writing an android app and using rxjava to handle user input events. Basically what I want to do is, emit when a button is clicked, and then drop subsequent emissions for some period of time afterwards (like a second or two), essentially to prevent having to process multiple clicks of the button.
I think throttleFirst
is what you want: https://github.com/Netflix/RxJava/wiki/Filtering-Observables#wiki-throttlefirst
For preventing fast clicks i use this code
RxView.clicks(your_view)
.throttleFirst(300, TimeUnit.MILLISECONDS)
.subscribe {
//on click
}
Continuing zsxwing's Answer:
If you're not using RxBinding library but only RxJava then,
io.reactivex.Observable.just(view_obj)
.throttleFirst(1, TimeUnit.SECONDS)// prevent rapid click for 1 seconds
.blockingSubscribe(o -> {
startActivity(...);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With