Android Handler(Timer)基本框架
Android Handler(Timer)基本框架
資料來源: http://android.tgbus.com/Android/tutorial/201108/362429.shtml
private Handler handler = new Handler( );
private Runnable runnable = new Runnable( )
{
public void run ( )
{
update( );
handler.postDelayed(this,1000);//持續定時執行
}
};
//第一次執行
handler.postDelayed(runnable,1000); // 開始Timer
//需要全部立即停止
handler.removeCallbacks(runnable); //全部停止Timer