Android handler.postdelay () every time minutes change on watch?

I want to postpone the message until the minute changes on the clock. i am currently using this

handler.postDelayed(drawRunner, 60000); 

but this delay lasts 60 seconds from the moment right now. what I want to do is delay the message until the minute changes on the clock.

, for example: lets say that the time on my phone is 4:15:29 , than I want to postpone it until 4:16:00 , and then the next 4:17:00 , etc.

Is there anyway to do this?

+4
source share
2 answers

You can access the current time:

 long time = System.currentTimeMillis(); 

After that, you can get the second part:

 int seconds = new Date(time).getSeconds(); 

Then you can subtract this from 60 and get sleep time.

 int sleepSecs = 60 - seconds; 

Then set to disable handler.postDelayed()

 handler.postDelayed(drawRunner, sleepSecs*1000); 

After the first use, you can use a constant 60,000 milliseconds of lull.

Note that getSeconds () can return 60 or 61 as the second value! Documentation

+4
source

Yes, you can use this Timer class to schedule a periodic task so you can change your clock time to any time period as needed.

0
source

All Articles