Edit: this is NOT the same as ProgressDialog doesn't show just flashes
I make sure to used AsyncTasks for network communications and file operations, showing an indeterminate, cancelable ProgressDialog until the task is complete, as I feel I properly should.
In some situations--slow mobile Internet connection, an older underpowered device--this may take some seconds. But the exact same task may complete very rapidly in other situations or on other devices, causing the ProgressDialog to show only for a fraction of an instant, basically flickering on the screen.
What is best practice here? I can think of several options:
- Leave it as is, knowing that some users will have that flickering effect.
- Force the ProgressDialog to stay visible for a minimum length of time (half a second, a second) before it disappears, even if the task has already completed--but I hate the idea of introducing artificial delays.
- Time the task and only show the ProgressDialog if the task takes more than a minimum set amount of time, such as half a second. The problem is this is not really a solution; if the task takes under that length of time, great; if the task takes a long time, great--but if the minimum time of 0.5 seconds and the task actually takes 0.7 seconds, then you have the same issue again... a brief flicker.
- If you can monitor the progress of the task, test it briefly and estimate, from the first fraction of a second or the first x percent, how long it should take to complete the task; if it is expected to take a while, then show the ProgressDialog. But this would be quite complex, and not every background task lends itself well to this sort of progress estimation.
What is the best approach? Is there an option I've missed? Is there a way to set the ProgressDialog so it only shows if there will be a noticeable delay? (I doubt there is, but it would be nice if there was some magic way). Is one of these the "standard" solution?