1

I am trying to make a media player which has a seekbar. As the seekbar should stop progress when pause is pressed or stop is pressed. I want to stop the thread accordingly. Moreover when back is pressed I want to cancel the thread again.

User97693321
  • 3,336
  • 7
  • 45
  • 69
abhishek
  • 1,434
  • 7
  • 39
  • 71
  • 4
    possible duplicate of [How to stop a java thread gracefully ?](http://stackoverflow.com/questions/3194545/how-to-stop-a-java-thread-gracefully) – Thilo Mar 19 '11 at 10:53
  • @NLV Thread.suspend is deprecated, because it won't release any locks the thread holds – Maaalte Mar 19 '11 at 11:37

1 Answers1

0
boolean running = true;
final Thread t = new Thread(new Runnable() {
    @Override
    public void run() {
        try {
            while(running){
                 //Your code
            }
        } catch (Exception e) {
        // TODO Auto-generated catch block
    e.printStackTrace();
    }
    //handler code

    }
});
t.start();

defining a "running" boolean will manage when the thread will execute its code, when you set running to false the seekbar will stop without interrupting or killing the thread.

Emond
  • 50,210
  • 11
  • 84
  • 115