Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is CountDownTimer accessing UI inside OnTick method?

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();
like image 792
uzay95 Avatar asked Dec 17 '22 13:12

uzay95


1 Answers

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.

like image 144
Ashwin Avatar answered Jan 10 '23 01:01

Ashwin