优化心跳定时器的代码

nx2024TEMP
Matthew 6 months ago
parent d795d35fd5
commit 85a82e745d

@ -411,7 +411,14 @@ public class MicroPhotoService extends Service {
Thread th = new Thread(runnable);
th.start();
mService.registerHeartbeatTimer(mService.mHeartbeatDuration);
long ts = System.currentTimeMillis();
long expectedHbTime = intent.getLongExtra("HeartbeatTime", ts);
long nextHbTime = expectedHbTime + mService.mHeartbeatDuration;
while (nextHbTime <= ts) {
nextHbTime += mService.mHeartbeatDuration;
}
long timeout = (expectedHbTime != 0) ? (nextHbTime - System.currentTimeMillis()) : mService.mHeartbeatDuration;
mService.registerHeartbeatTimer(timeout);
try {

Loading…
Cancel
Save