fatal exception in android Timer

前端 未结 4 1614
旧时难觅i
旧时难觅i 2021-01-28 06:27

in my android application i\'m using Timer schedule.but getting Timer-0 fatal exception as below.how can i remove it.i have also mentioned code below -

01-28 13:         


        
4条回答
  •  無奈伤痛
    2021-01-28 06:56

    You can use a CountDownTimer instead of the Timer :

    Timer timer = new CountDownTimer(Long.MAX_VALUE, 1000) {
        public void onTick(long millisUntilFinished) {
            // the code in the method run
        }
    
        public void onFinish() {
    
        }
    };
    

    The methods onTick and onFinish will be called in the UI thread.

    To make the timer start performing its action, run: timer.start()

提交回复
热议问题