Skip to content Skip to sidebar Skip to footer

Onprogressupdate Execution

I am practicing the working of the AsyncTask and with that purpose I wanted to use the onProgressUpdate function. Currently in my program I have UI that lets the user choose an inp

Solution 1:

Because it is going through your loop faster than you see it

for (int i = 1; i <= time / 1000; i++) {
                publishProgress(i, time);

You don't need the loop there. Just sleep for whatever amount of time then show your progress and have the sleep() and the publishProgress() in the loop. Something like

try {
       int time = 0;
       for (int i = 1; i <= time / 1000; i++) {

        if (input[1].equalsIgnoreCase("")) {
            time = 0;
        } else {
            time = Integer.parseInt(input[1]) * 1000;
                publishProgress(time);
            }
            Thread.sleep(time);
        }

Although, I'm not sure what input actually contains but you might want input[i]. It looks like its always going to be the same otherwise.

Also, CountDownTimer would be good for this I would think.

Post a Comment for "Onprogressupdate Execution"