Reputation: 2998
When I do some processing in the background thread and wants to update the UI using runOnUiThread(), the code inside the function is running successfully without any error, but the UI gets rendered only if the user touches the screen. Otherwise, it's rendering consistently.
Why it's rendering only after touching the screen ?
Upvotes: 0
Views: 421
Reputation: 11921
It's possible that an operation is blocking (for example notifying an adapter too often) your ui thread and gets unblocked with an interrupt occurs. Touching the screen is an interrupt in your scenario.
If you paste your code maybe we can find an exact solution.
Edit: Debounce example code with RxJava
yourSearchObservable
.throttleLast(100, TimeUnit.MILLISECONDS)
.debounce(200, TimeUnit.MILLISECONDS)
.onBackpressureLatest()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
searchResults -> {
// Your success
} ,
() -> {
// Error
}
));
Upvotes: 2
Reputation: 159
Try using callbacks or android.os.Handler.post() to interact with the Main Thread
Upvotes: 1
Reputation: 3282
It is possible if your screen gets overlapped by another screen. This causing Activity to move to paused state (.onPause()) method. when you touch it again, it become foreground again so can receive UI update events
Upvotes: 2