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 aga开发者_开发知识库in.
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.
精彩评论