I'm running into a bit of an issue with RxBinding....
# android
f
I'm running into a bit of an issue with RxBinding. I wasn't really sure whether to post it here or in #rx, but given that it's Android specific I'll just post it here for now (or whether it's even relevant to this Slack given that it's not Kotlin specific). Anyway, I've got a spinner for which I want to get selections in a reactive way. To achieve this I'm using RxBinding, and it works fine when you subscribe, producing a single call to
onNext
. However when I turn the phone it produces unexpected (as far as I understand it) results. After turning the phone
onNext
always produces either two or three values. If the initial value is still selected it produces this twice. If another value has already been selected it produces the original value once and the selected value twice. I've got the following in my `OnCreateView`:
Copy code
val adapter = ArrayAdapter.createFromResource(
        activity,
        R.array.geo_array,
        android.R.layout.simple_spinner_item
)
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner?.adapter = adapter
val countries = resources.getStringArray(R.array.geo_array)
RxJavaInterop.toV2Observable(spinner?.itemSelections()?.map { countries[it] }).subscribe { Timber.d("onNext $it") }
So every time I turn the phone a new adapter is set on the spinner (which should replace the old one) and a new subscriber is added. I've tried storing the
disposable
produced by the subscribe method and disposing this in
onDestroyView
, however it still happens. Anyone knows what exactly I'm missing and why it's doing all those onNext calls after turning the phone? Is it just some fundamental understanding of Rx that I lack?