1. The purpose of this post
I would demo how to solve this error when using do some UI operations in a thread:
The code(updateUI from a thread inside an activity or fragment):
Run the app, we get this error:
3. Solution and Code
Because android system do not allow the UI operations to run in the non-UI thread, so you can change the code like this:
Build and run the app, everything works fine.