Displaying a Running Timer
Next, you need to update the display at regular intervals so that the current time is displayed. On Android this is not as straightforward as it may seem.
The activity’s user interface runs in a single thread. If you block that thread for too long, the Android OS thinks your application has frozen, and you will get the Application Not Responding (ANR) dialog box. Strict mode (which you added earlier) will tell you about potential issues that could cause your application to become unresponsive.
One solution is to create an extra thread and do all the work in that thread; in this way, you would not block the main UI thread and would stop any ANRs. Unfortunately, though, simply using standard Java timers or threads is ...
Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications 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.