How to set a timer in android

前端 未结 13 1846
天命终不由人
天命终不由人 2020-11-22 06:43

What is the proper way to set a timer in android in order to kick off a task (a function that I create which does not change the UI)? Use this the Java way: http://docs.ora

13条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 07:16

    I hope this one is helpful and may take less efforts to implement, Android CountDownTimer class

    e.g.

     new CountDownTimer(30000, 1000) {
          public void onTick(long millisUntilFinished) {
              mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
          }
    
          public void onFinish() {
              mTextField.setText("done!");
          }  
    }.start();
    

提交回复
热议问题