Android开发:如何安全的中止一个自定义线程Thread
经研究,我推荐这种写法:
/*自定义线程*/class MyThread implements Runnable{public void run() {// TODO Auto-generated method stub // 定义自己的变量 while(!Thread.currentThread().isInterrupted()){try { doSomeThingNeed();//需要更新的操作 //休眠控制最大帧率为每秒3绘制30次Thread.sleep(30);} catch (Exception e) {// TODO: handle exceptionLog.v(tag2, "DrawSurfaceView:绘制失败...");Thread.currentThread().interrupt();}}}