HandleTread学习

HandleThread学习

//创建一个线程,线程名字:handler-thread handlerThread = new HandlerThread( "handler-thread") ;
//开启一个线程 handlerThread.start();
//在这个线程中创建一个handler对象

handlerCapture = new Handler( handlerThread.getLooper() ){
     @Override      
public void handleMessage(Message msg) {
         super.handleMessage(msg);
         //这个方法是运行在 handler-thread 线程中的 ,可以执行耗时操        }
 };
 if (isStopCaptureClick(stopOpreationTime)==true){
     stopOpreationTime=0;
     handlerCapture=null;
     handlerThread.quit();
 }
 if (handlerCapture!=null) {
     handlerCapture.postDelayed(new Runnable() {
         @Override            public void run() {
             if (stopOpreationTime==0&& CaptureDelayTime!=0){
                 soundPool.play(0, 0, 0, 0, 0, 0);
                 stopOpreationTime=0;
             }else {
                 soundPool.play(music, 1, 1, 0, 0, 1);
                 stopOpreationTime = 0;
             }
         }
     }, delaySecond);
 }
}

你可能感兴趣的:(Android开发)