How to stop Handler Runnable?

前端 未结 4 2028
半阙折子戏
半阙折子戏 2020-12-24 07:13

I am using a handler in the following program and I want to stop it when i=5 but the handler doesn\'t stop and run continuously.

   b1.setOnClickListener(ne         


        
4条回答
  •  天命终不由人
    2020-12-24 07:49

    Just saw this question. I would use CountDownTimer() instead. Run it for 5 seconds total and every second:

    new CountDownTimer(5000, 1000) {
        public void onTick(long milsecRemain) {
            // Code to run every second
            Log.i("Seconds left", String.valueOf(milsecRemain/1000));
    }
        public void onFinish() {
            // 10 seconds have passed
        }
    }.start();
    

提交回复
热议问题