Communicating with the UI Thread

A thread sometimes also needs to communicate with the UI thread, either in between the execution of the thread or at the end of the execution of a thread. Only objects running on the UI thread have access to other objects on that thread. Because tasks that you run on a thread from a thread pool aren't running on your UI thread, they don't have access to UI objects. For example, if you have the task of downloading a large file from a server, then showing the progress of the download would be a good practice. In order to show this progress, your thread must communicate with the UI thread to display the progress as a percentage.

Data from a background thread could communicate with the UI thread using a Handler ...

Get Expert Android Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.