Richeek Dey
Richeek Dey

Reputation: 257

Implementing Timer in Android

I wish to implement a timer which runs for 60 seconds. So basically, my app receives heart rate values from a device. I wish to capture 60 seconds of these values and then pass it on to a function for further calculation. I have seen the various solutions posted, but I am confused. Where do I put the code to store the values? Can someone please post a generic code wherein I can understand where exactly I am going to be receiving my HR values and storing them?

Upvotes: 0

Views: 36

Answers (1)

Shabbir Dhangot
Shabbir Dhangot

Reputation: 9141

there Are several ways to perform that.

  1. Using Handler()

    //Start Code for Timer
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
           //This will call after 60 second. Call your Function here 
        }
    },(1000*60));
    
  2. CountDownTimer

    See Documentation here

    new CountDownTimer((60*1000), 1000) {
    
        public void onTick(long millisUntilFinished) {
            // this will call in every 1 sec
        }
    
        public void onFinish() {
            //This will call after 60 second. Call your Function here 
        }
    }.start();
    

Upvotes: 1

Related Questions