Providing deterministic progress feedback
Knowing that something is happening is a great relief to our users, but they might be getting impatient and wondering how much longer they need to wait. Let's show them how we're getting on by adding a progress bar to our dialog.
Remember that we aren't allowed to update the user interface directly from doInBackground()
, because we aren't on the main thread. How, then, can we tell the main thread to make these updates for us?
AsyncTask
comes with a handy callback method for this, whose signature we saw at the beginning of the chapter:
protected void onProgressUpdate(Progress... values)
We can override onProgressUpdate()
to update the user interface from the main thread, but when does it get called and where ...
Get Asynchronous Android Programming - Second Edition 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.