How CountDownTimer
is accessing UI inside onTick
method?
(new CountDownTimer(10000,1000){
@Override
public void onFinish() {
// TODO Auto-generated method stub
}
@Override
public void onTick(long millisUntilFinished) {
TextView tv = (TextView)findViewById(R.id.tvLCD);
tv.setText(Long.toString(millisUntilFinished));
}
}).start();
From the links( GreCode - Handler ) in the answer given by @Sergey Glotov, it is clear that countdown timer does not use a seperate thread at all. That is the reason you are able to access the all the UI elements. I don't know why they have used a handler. But it does not spawn a new thread. It runs on the UI thread itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With