开发者

Android Replacing Thread.sleep with alarms using AlarmManager

开发者 https://www.devze.com 2023-03-14 23:25 出处:网络
I want to replace the Thread.sleep(time) calls in my code with alarms set with AlarmManager. How can I return to the proceeding code after the alarm has elapsed. It looks l开发者_运维问答ike I use a P

I want to replace the Thread.sleep(time) calls in my code with alarms set with AlarmManager. How can I return to the proceeding code after the alarm has elapsed. It looks l开发者_运维问答ike I use a PendingIntent but how to I point it back to the proceeding code after the time has elapsed?.


Well, it depends on what values you have for time. If you are sleeping for 100ms, you definitely don't want to use AlarmManager, as piotrpo suggests. However, if you are sleeping for several minutes, then AlarmManager is appropriate.

AlarmManger and PendingIntents impose big overheads, so be careful with using them.


Alarm manager is not designed to something like that. .sleep() is also not good. Please read about Timer and Handler classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号