December 2013
Beginner
416 pages
12h 45m
English
For the application to work as a bicycle computer, the counter needs to be updated frequently. This update is based on how much time has passed since the timer was started. There are two parts to solving this issue: updating the display and doing it at regular intervals. Let’s first update the display.
1. Create two new properties of type long in the TimerActivity class called startedAt and lastStopped:
protected long startedAt;protected long lastStopped;
2. In the clickedStart method, set startedAt to contain the current time in milliseconds:
startedAt = System.currentTimeMillis();
And in the clickedStop method, set lastStopped to contain the current time in milliseconds:
Read now
Unlock full access