简体   繁体   中英

Should I use setAlarm, setExact or setRepeat Alarm?

For setAlarm() parameter : Should I use SystemClock.elapsedRealtime(), calander,getTimemillise or something?

Because Alarm is coming fine, but when I manually go to my Android phone date & time settings and change the time (not past, but future time), alarm is not coming and triggers immediately.

This is an intended behaviour as specified in the official Alarm Manager docs for all the set methods.

If the stated trigger time is in the past, the alarm will be triggered immediately.

to manage you can try to cancel such alarms with past trigger time in your reciever .

How to choose between System.currentTimeMillis() vs SystemClock.elapsedRealtime()

As the link specifies the :-

  1. The first method, will give you the standard "wall" clock (time and date) expressing milliseconds and is affected by and changes in time and date from the settings.

  2. While the second method, return the time in milliseconds since the system was booted, and including sleep time. Hence would not be affected with the changes in the settings so it is the recommend basis for general purpose interval timing.

So if you do not want the time to be dependent on the time-zonal changes , it is better to use the second method.Otherwise you need to handle it as mentioned before.

As compared to other alternatives like Date or Calender , it is better to use currentTimeMillis() due to performance benefits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM