I have been using ServiceStartAt to start the service and found out that the difference in scheduled and actual start times can be several minutes. See the log below:
After reading about AlarmManager, I have found out that the problem can be with the applications that have TargetSDKVersion 19 or above and use the AlarmManager set function.06:03:06 - Next Start at 19/05/15 21:30:00
Ticks - 1432036800000
21:34:02 *** Service start ***
Intent (Intent) Intent { flg=0x4 cmp=com.NotifyMe/.notificationservice (has extras) }
Extras Bundle[{android.intent.extra.ALARM_TARGET_TIME=1432036800000, android.intent.extra.ALARM_COUNT=1}]
21:34:04 - Next Start at 20/05/15 06:00:00
Ticks - 1432067400000
06:07:08 *** Service start ***
Intent (Intent) Intent { flg=0x4 cmp=com.NotifyMe/.notificationservice (has extras) }
Extras Bundle[{android.intent.extra.ALARM_TARGET_TIME=1432067400000, android.intent.extra.ALARM_COUNT=1}]
Data null
06:07:12 - Next Start at 20/05/15 21:30:00
Ticks - 1432123200000
The recommended method to use is setExactpublic void set (int type, long triggerAtMillis, PendingIntent operation)
Note: Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time,
but may be deferred and delivered some time later. The OS will use this policy in order to "batch" alarms together across the entire system, minimizing the number of times the device needs to "wake up" and minimizing battery use. In general, alarms scheduled in the near future will not be deferred as long as alarms scheduled far in the future.
Applications whose targetSdkVersion is before API 19 will continue to get the previous alarm behavior: all of their scheduled alarms will be treated as exact.
I did it using inline Java but the question for Erel is, that maybe he could implement it in the B4A Core.jar for StartServiceAt function?public void setExact (int type, long triggerAtMillis, PendingIntent operation)
Schedule an alarm to be delivered precisely at the stated time.
This method is like set(int, long, PendingIntent), but does not permit the OS to adjust the delivery time. The alarm will be delivered as nearly as possible to the requested trigger time.
Note: only alarms for which there is a strong demand for exact-time delivery (such as an alarm clock ringing at the requested time) should be scheduled as exact. Applications are strongly discouraged from using exact alarms unnecessarily as they reduce the OS's ability to minimize battery use.