http://zhidao.baidu.com/question/299079849.html
android,启动了一个子线程,这个子线程是一个死循环,不成的打印“Hello”。 现在要实现点击一个Button,让这个子线程终止,用什么方法啊? stop()不起作用,destroy()有异常,Handler貌似也解决不了,因为是一个线程。。。答案如下:线程像这样:Thread{ boolean flag = fase; run(){ while(!flag){ } }}Thread t = new Thread();t.start();-----------------------------------------------------要终止循环,只需要这样t.flag=true;================================================还有一种方式 线程像这样:Thread{ run(){ while(true){ Thread.sleep(xxxx); } }}Thread t = new Thread();t.start();--------------------------------------------要终止循环,只需要这样t.interrupte();但是这里要注意调用的时机,要在子线程执行了run方法里面的sleep(xxxx)后xxxx时间之内调用。也就是子线程会睡一会,醒一会,睡一会,醒一会,要在子线程睡着的时候调用。