[英]android handler .postdelay() everytime minute change on clock?
i want to delay post till the minute change on clock. 我想延迟发布直到时钟的分钟变化。 currently i am using this 目前我正在使用
handler.postDelayed(drawRunner, 60000);
but this delay post 60 seconds from the time right now. 但是此延迟从现在的时间开始持续60秒。 what i want to do is delay the post till minute change on the clock. 我想做的是将帖子延迟到时钟的分钟更改。
for example: lets say time on my phone is 4:15:29
than i want to delay it till the time 4:16:00
and then the next is 4:17:00
and so on. 例如:可以说,时间在我的手机是4:15:29
,比我想它推迟到时候4:16:00
,然后接下来就是4:17:00
等。
is there anyway to do this?? 反正有这样做吗?
You can access the current time by: 您可以通过以下方式访问当前时间:
long time = System.currentTimeMillis();
After you have that, you can get the second part of it by: 完成后,可以通过以下方法获得第二部分:
int seconds = new Date(time).getSeconds();
Then you can substract that from 60, and get the sleep time. 然后,您可以从60中减去该值,并获得睡眠时间。
int sleepSecs = 60 - seconds;
Then set that to sleep time to handler.postDelayed()
然后将其睡眠时间设置为handler.postDelayed()
handler.postDelayed(drawRunner, sleepSecs*1000);
After the first time you use this, you can use a constant 60000 millisecond sleeptime. 首次使用此功能后,您可以使用恒定的60000毫秒的睡眠时间。
Please note, that getSeconds() can return 60 or 61 as second value! 请注意,getSeconds()可以返回60或61作为第二个值! Documentation 文献资料
是的,您可以使用此 Timer类来安排定期任务,这样您就可以根据需要在任何时间段内更改Clock时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.