I am facing this error from RxJava
Android “Only the original thread that created a view hierarchy can touch its views.”
code i used
Log.d(TAG, "stratObserving:qw ${Thread.currentThread()}")
(application as? App)?.relayPages
?.doAfterNext{
hideLoading()
}
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe({
"data found ${it.size}".log()
pageAdapter.setPageList(it)
rvAyahsPages.scrollToPosition(pos)
"data pageAdapter ${pageAdapter.itemCount} , ${Thread.currentThread()}".log()
foundState()
}, {
"error ${it.message}".log()
})
?.addTo(model.bg)
private fun foundState() {
spShowAyahs?.visibility = View.GONE
tvNoQuranData?.visibility = View.GONE
rvAyahsPages?.visibility = View.VISIBLE
"found $rvAyahsPages $spShowAyahs".log()
}
however
Log.d(TAG, "stratObserving:qw ${Thread.currentThread()}")
print Thread [main,5,main]
and
Log.d(TAG, "stratObserving:qw ${Thread.currentThread()}")
print Thread [main,5,main]
[Note]
This Question differs from "Android “Only the original thread that created a view hierarchy can touch its views.”" answers that the solution was to run on MainThread but here it actually run on MainThread
[Edit] problem was of ordering of operator so replace doAfterNext with observeOn.