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.
精彩评论