Tuesday, June 18, 2019

Trying to use Android UI components from the wrong thread may do something strange

Today I was making an Android app react to websocket events. When I tried to update UI based on the events, I found strange behavior like the layout not updating when a view was set to gone even though the view was no longer visible. Then I realized that the websocket library delivers the events on a different thread. Using a Handler to enqueue the UI-related work for the main thread fixed the problem.

No comments:

Post a Comment