Code example for Timer

Methods: scheduleAtFixedRate

0
 
	/** 
	 * Thread to update clock every second 
	 */ 
	public void start() { 
		timer = new Timer();
		timer.scheduleAtFixedRate(new TimerTask() {
			public void run() { 
				final String time = DateUtils.formatDateTime(getContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME);
				if (!time.equals(lastTime)) {
					handler.post(new Runnable() {
						public void run() { 
							timeView.setText(time);
						} 
					}); 
					lastTime = time;
				} 
			} 
		}, 0, 1000); // every second 
	} 
Stop searching for code, let great code find you!  Add Codota to your java IDE