dev_android
dev_android

Reputation: 8818

Android on screen timer

I want to show a timer on the screen and the count down will continue on screen. It will also give some sound alert in certain time interval. There may be multiple timer running at the same time. What is best way to implement this type timer system? Should I run a thread for each time any timer starts and change the time display using UIThread()? There is some better way to implement it? Anyone can give me sample code for that?

Upvotes: 0

Views: 1702

Answers (1)

Paresh Mayani
Paresh Mayani

Reputation: 128428

You can implement CountDownTimer.

For example:

new CountDownTimer(5000, 1000) {

    public void onTick(long millisUntilFinished) {
         txtView.setText(String.valueOf(millisUntilFinished / 1000));

    }
    public void onFinish() {
    }
 }.start();

Upvotes: 7

Related Questions