Wednesday, April 25, 2018

Android UI changes might not appear if a lot of work occupies the main thread

Today I worked with an Android activity that is supposed to do some initialization work and display the current status in a TextView. I found that, even though the setText call was before all the work, and though the progress spinner continued to spin, the new text didn't appear until after the work was done. Apparently this happens when the UI thread is tied up (due to the work being done); Android doesn't get a chance to redraw the label. If the UI thread is busy, other strange things can happen like visual stalling/blankness when unlocking the phone. Using an AsyncTask should keep things smooth for the user.

No comments:

Post a Comment