Skip to content Skip to sidebar Skip to footer

How To Stop A Thread(progressbar) In Android

i have made a countdown timer using progressbar and a thread,Now i want to stop the progress at the same time when user clicks on a button.I have tried thread.stop(),but it says th

Solution 1:

 Thread th = new Thread(new Runnable() {
             public void run() { ....

 th.start();//starts

 th.interrupt();//this stops.

and use

 while (progressStatus < 100 && (!Thread.currentThread().isInterrupted())){....

instead of

 while (progressStatus < 100) {....

Solution 2:

Now i want to stop the progress at the same time when user clicks on a button.I have tried thread.stop()

Thread.stop() is deprecated and you should not use it. The basic concept to understand is that a thread terminates is execution when the last line of code of his run method is executed. In the case of your "ProgressBar Thread*, when the user press the button, you have to set the exit condition of your while-loop (progressStatus = 100) in order to make it terminate


Post a Comment for "How To Stop A Thread(progressbar) In Android"