Handler+Runnable方式

private Handler handler = new Handler();

private Runnable runnable = new Runnable(){

       public void run(){

               update();

               handler.postDelayed(runnable.this,1000);

       }

};

handler.postDelayed(runnable,1000); //开始timer

handler.removeCallbacks(runnable);  //停止Timer

ps:当然runnable也可以用Implements的方式.

感觉timer的方式更适合启用多线程!

你可能感兴趣的:(Runnable)