Multiple choice

Which of the following codes will record the current system time and send a message to the handler starting the timer and remove any existing message before sending the next one?

  1. Private void startTimer(){
       mSt=System.currentTimeMillis();
       mHandler.removeMessages(0);
       mHandler.sendEmptyMessage(0);
    }
    
  2. Private void startTimer(){
       mSt=System.currentTime();
       mHandler.removeMessages(0);
       mHandler.sendEmptyMessage(0);
    }
    
  3. Private void startTimer(){
       mSt=System.currentTimeMillis();
       mHandler.removeMessage(0);
       mHandler.sendEmptyMessage(0);
    }
    
  4. Private void startTimer(){
       mSt=System.currentTimeMillis();
       mHandler.removeMessages(0);
       mHandler.sendEmptyMessages(0);
    }
    
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The code for recording the current system time and sending a message to the handler, starting the timer and removing any existing messages before sending the next one is as follows:

Private void startTimer() {
 mSt = System.currentTimeMillis();
 mHandler.removeMessages(0);
 mHandler.sendEmptyMessage(0);
}