This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
This is homework, but I'm not looking for someone to do it for me. I'm just a little lost.
The goal is to create a countdown timer just using System.currentTimeMillis(). The exercise is to show how to use AsyncTask properly to avoid ANR.
We were told to use Thread.sleep to space out checks so that the system doesn't get bogged down, but of course Thread.sleep isn't exact and works in *roughly* the number of ms you enter. So sometimes the final check to see if a second has passed and if the UI should update is 1244ms, or 1100 ms. Which means on occasion my UI will skip a number entirely.
I've created an otherwise fully functional countdown timer (it starts, counts down correctly, and ends at the right time) aside from it updating the seconds left appropriately.
My onProgressUpdate simply does the math for seconds vs minutes of remaining time, and plugs those numbers into a pair of TextEdits. Nothing fancy there, and it works.
I know the error has to do with Thread.sleep not being accurate, and while I know that, I don't quite understand the logic involved to work around it.
My doInBackground below:
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/javahelp/co...