- 一種利用handler更新時(shí)間的方法
Handler mHandler=new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case SON_THREAD:
updateTimes();
sendEmptyMessageDelayed(SON_THREAD, 1000);
break;
case FATHER_THREAD:
tv.setBackgroundColor(Color.LTGRAY);
break;
default:
break;
}
};
};
updateTimes()
是獲取當(dāng)前時(shí)間并將時(shí)間顯示出來(lái)的方法;
利用handler延遲發(fā)送消息循環(huán)調(diào)用達(dá)到以秒為周期實(shí)時(shí)更新時(shí)間的目的。
這種循環(huán)處理的方法即使當(dāng)handler接收到其他消息也不會(huì)影響對(duì)該消息的處理噪生,并且自身也不會(huì)被打斷赏壹。
錯(cuò)誤
'<>'operator is not allowed for source level below 1.7
右鍵工程->property->java compiler->勾選Enable project specific settings->Compiler compliance level--選擇1.7andorid 鬧鐘
Android系統(tǒng)之鬧鐘模塊淺析