Wednesday, 30 January 2013

Lengthen the Background Work | Android Tutorial pdf

Lengthen the Background Work

First, let us make the background work take a bit longer, so we have a bigger "window" in which to test whether our pause-and-resume logic works. It is also helpful, in our case, to synchronize our loop with our progress, so rather than counting 0 to 20 by 1, we should count from 0 to 10000 by 200, so the loop counter and progress are the same.
In the longTask Runnable, change the loop to look like this:
for (int i=progress;
i<10000;
i+=200) {
doSomeLongWork(200);
}

No comments: