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();
You can get access to UI from thread by
Activity.runOnUiTread(),View.post(),View.postDelayed()or viaHandler.CountDownTimerusesHandlerfor this purpose (source).Read this article for understanding how to use all of these methods.