- Learning Concurrency in Kotlin
- Miguel Angel Castiblanco Torres
- 102字
- 2021-08-05 10:46:47
CalledFromWrongThreadException
Android will throw a CalledFromWrongThreadException whenever a thread that didn't create a view hierarchy tries to update its views. In practical terms, this exception will happen whenever a thread other than the UI thread updates a view. This is because the UI thread is the only one that can create view hierarchies, so it will always be the one that can update them.
It's important to guarantee that code that will update the UI is running in the UI thread. In our example, we will update a label on the UI thread after calling a service on a background thread.