重庆建设网站的公司,wordpress手机速度插件,知名建筑类的网站,开网店教程心想着也就是更新精确到分钟#xff0c;不用精确到秒#xff0c;定时器就没有必要#xff0c;系统是有广播Intent.ACTION_TIME_TICK可以直接用
动态注册广播
主方法里面调用一下
//要先设置一下当前时间#xff0c;不然刷新时间会等到1分钟后再刷新
tv_HM.setText(getHM…心想着也就是更新精确到分钟不用精确到秒定时器就没有必要系统是有广播Intent.ACTION_TIME_TICK可以直接用
动态注册广播
主方法里面调用一下
//要先设置一下当前时间不然刷新时间会等到1分钟后再刷新
tv_HM.setText(getHM());IntentFilter filternew IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
registerReceiver(receiver,filter);
接收广播并处理
private final BroadcastReceiver receiver new BroadcastReceiver() {Overridepublic void onReceive(Context context, Intent intent) {String action intent.getAction();if (action.equals(Intent.ACTION_TIME_TICK)) {tv_HM.setText(getHM());}}};
精确到时:分的方法 public String getHM(){Calendar c Calendar.getInstance();int hour c.get(Calendar.HOUR_OF_DAY);int minute c.get(Calendar.MINUTE);return hour : minute;}