在TimerTask中用handler发消息,而在handlermsg中收不到消息,什么原因

李天勇 发布于 2013/04/20 14:30
阅读 442
收藏 0

先看下代码:

private void initData() 
{
        private java.util.Timer refresh_satellite;
	refresh_satellite = new java.util.Timer();
	refresh_satellite.schedule(task,1000, 1000);		
		
}
TimerTask task = new TimerTask(){     
	    
        public void run() {     
            Message message = new Message();         
            message.what = 1;         
            handler.sendMessage(message); 
            Log.e("msg","msg.what="+ message.what);
        }     
             
    };
Handler handler = new Handler(){
		public void handlerMsg(Message msg){
			Log.e("msg2","---->>>msg2.what="+msg.what);
			switch (msg.what) {
			case 1:
				TunerQulity = ICDL.getTunerQulity(1);
				Log.e("c","ICDL.getTunerQulity(1)="+ICDL.getTunerQulity(1));
				TunerStrength = ICDL.checkTunerStrength(1);
				//Log.e("d","ICDL.checkTunerStrength(1)="+(0-ICDL.checkTunerStrength(1)));
				quality_bar.setProgress((int)TunerQulity);
				stength_bar.setProgress((int)TunerStrength);
				quality_textview.setText(TunerQulity+"");
				strength_textview.setText((0-TunerStrength)+"");
				break;

			default:
				break;
			}
			super.handleMessage(msg);
		}
	};

以上的代码都在同一个类里,结果在handlermsg方法里打印msg2打印不出来,打断点,单步运行也走不到这里面来,不知道什么原因,请高手帮忙看看

加载中
返回顶部
顶部