Search code examples
androidtimeralarm

Android compare to a time to current time continuously


I am making an app which need to compare two date and time continuously. I just saw some example which just compare once. I think I can use timer to repeat a method but it seem not very efficient. Anyone did this before?


Solution

  • Maybe you can use postDelayed like below.

    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() {
        @Override 
        public void run() { 
            compareTime();
        } 
    }, 5000); 
    

    replace 5000 with your own interval milliseconds.