kaushikgopal / RxJava-Android-Samples

Learning RxJava for Android by example
Apache License 2.0
7.55k stars 1.37k forks source link

GUI elements must not be accessed from non-main threads #94

Closed tmtron closed 7 years ago

tmtron commented 7 years ago

As far as I understand the following code from DebounceSearchEmitterFragment.java#L76:

_disposable = RxJavaInterop.toV2Observable(RxTextView.textChangeEvents(_inputSearchText))
              .debounce(400, TimeUnit.MILLISECONDS)// default Scheduler is Computation
              .filter(changes -> isNotNullOrEmpty(_inputSearchText.getText().toString()))
              .observeOn(AndroidSchedulers.mainThread())
              .subscribeWith(_getSearchObserver());

filter() accesses the GUI element _inputSearchText, which it must not do: see StackOverflow: Is it okay to read data from UI elements in another thread?

Instead the text should be read from the change-event like this: .filter(changes -> isNotNullOrEmpty(changes.text().toString()))

kaushikgopal commented 7 years ago

great catch! do you feel like submitting a mini-PR instead :) ? i'm happy to make the change, but would like to attribute the credit to you.