0

If my activity launches a Runnable and then the device goes into sleep mode, will the Runnable be paused and then continue from where it left off after coming out of sleep mode?

4

1 回答 1

0

是的,它确实。

但是,当手机处于睡眠状态时,您不会过期。手机处于睡眠状态时不计算时间,因此您会得到以下(可能)不直观的行为:

t= 0s: 设置超时 1 分钟
t= 20s: 手机进入睡眠
t= 40s: 手机唤醒
t= 60s: 你期待你的闹钟,但你没有得到它
t= 80s: 你的闹钟因为 20s 睡眠而触发时间没有计算!

如果你不喜欢这个,你可以使用AlarmManager类。它更难使用并且需要更多的系统资源,但它会计算睡眠时间并唤醒设备。

于 2014-11-17T19:56:28.297 回答