android_タイマー_タイミングループタスク




myTimerTask timerTask = new MyTimerTask();  
Timer timer = new Timer(true);  
timer.schedule(timerTask, 0, 1000);//   

// , message  
private class myTimerTask extends TimerTask {   
    @Override  
    public void run() {  
		Message message = new Message();  
		message.what = 2;  
		myHandler.sendMessage(message);  // message
    }  
}  
  
//Handler message   
Handler myHandler = new Handler() {  
    //    
    public void handleMessage(Message msg) {  
        switch (msg.what) {  
        case 1:  
			//UI 
			break;  
        case 2:  
			//UI 
            break;  
        }  
        super.handleMessage(msg);  
    }  
};  


//---------------------- -------------------------
// 
// ,  
Message message = handler.obtainMessage(1);     
handler.sendMessageDelayed(message, 1000); // message


final Handler handler = new Handler(){ 
	public void handleMessage(Message msg){         // handle message 
		switch (msg.what) { 
		case 1: 
			//UI   

			Message message = handler.obtainMessage(1); 
			handler.sendMessageDelayed(message, 1000);     // message ,  
		} 
		super.handleMessage(msg); 
	} 
};