- 一种利用handler更新时间的方法
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()
是获取当前时间并将时间显示出来的方法;
利用handler延迟发送消息循环调用达到以秒为周期实时更新时间的目的。
这种循环处理的方法即使当handler接收到其他消息也不会影响对该消息的处理,并且自身也不会被打断。
错误
'<>'operator is not allowed for source level below 1.7
右键工程->property->java compiler->勾选Enable project specific settings->Compiler compliance level--选择1.7andorid 闹钟
Android系统之闹钟模块浅析