1

I've a problem with RxCompoundButton, as soon as i subscribe to it, it will emit a default value, and it's not what i want. Is this behaviour expected ?

RxCompoundButton.checkedChanges(btOneWayFlag)
        .debounce(0, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
        .subscribe(notifyOneWayChecked);
yosriz
  • 10,147
  • 2
  • 24
  • 38

1 Answers1

3

Yes, you can see it in docs:

Note: A value will be emitted immediately on subscribe.

This is the behavior for all view that have 'state', that makes sense, as otherwise you will not get notify about the initial value of the view when subscribed, but will react only on first change.
You can also note this from the custom type of the returned Observable - InitialValueObservable.

If you don't want this behavior you can use skipInitialValue(), this is a special operator at the custom InitialValueObservable:

RxCompoundButton.checkedChanges(btOneWayFlag)
       .skipInitialValue()
       .debounce(0, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
       .subscribe(notifyOneWayChecked);
yosriz
  • 10,147
  • 2
  • 24
  • 38