重复执行某段代码

用handler就可以了
private Handler handler = new Handler();

private Runnable runnable = new Runnable() {
	public void run() {
		update();
		handler.postDelayed(this, 5000);
	}
};

开始计时
handler.removeCallbacks(runnable);
handler.postDelayed(runnable, 5000); 

停止计时
handler.removeCallbacks(runnable);

你可能感兴趣的:(android)